• Register a free account to view all forum content. Click here to create your own account.

Error: playername is not a valid member of Workspace. How to fix?

Joined
Jan 6, 2019
Messages
4
Roblox
TCAGamingAndMore
I'm making an admin gui for my game, in that gui there's a button that's supposed to set WalkSpeed to 100, and the same with JumpPower for the local player. Please help! Screenshot (2) - Copy.png
 
Joined
Nov 10, 2018
Messages
112
Ratings
11
Roblox
MythicalShade
Instead of doing local playername = script.Parent.Parent..., why not just do local player = game.Players.LocalPlayer to index the player, then get the name from there? Also, instead of trying to find the character in workspace, you can just get the player's character by using local character = game.Players.LocalPlayer.Character

This is what the correct code looks like.
Code:
local player = game:GetService("Players").LocalPlayer -- get the player
local character = player.CharacterAdded:Wait() -- get the character (wait for it to spawn)
local humanoid = character:FindFirstChild("Humanoid") -- get character's humanoid

script.Parent.MouseButton1Click:Connect(function()
    print("Clicked!")
    if humanoid.WalkSpeed == 16 and humanoid.JumpPower == 50 then
        humanoid.WalkSpeed = 1
        humanoid.JumpPower = 100
    else
        humanoid.WalkSpeed = 16
        humanoid.JumpPower = 50
    end
end)
 
Joined
Jan 6, 2019
Messages
4
Roblox
TCAGamingAndMore
Your script worked fine, but i still got this error message... I've never seen this error before, so i dont know what to do because of that. Screenshot (3).png
Post automatically merged:

Fixed it. I changed the "FindFirstChild("Humanoid")" to "WaitForChild("Humanoid")". Still, Thank you alot for your original fix!
Code:
local player = game:GetService("Players").LocalPlayer
local character = player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
print(player)

script.Parent.MouseButton1Click:Connect(function()
    print("Clicked")
    if humanoid.WalkSpeed == 16 then
        print(true)
        humanoid.WalkSpeed = 100
        humanoid.JumpPower = 100
        print("Changed")
    else
        print(false)
        humanoid.WalkSpeed = 16
        humanoid.JumpPower = 50
        print("Changed")
    end
end)
 
Last edited: