Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

[Solved] Player not valid member of workspace??

Asked by 1 year ago
Edited 1 year ago

I am trying to make a local variable for my local script in a Gui Button. I am trying to identify the player's house. When a player spawns their house in workspace the house model is called (I am using my username as an example): theking66hayday'sHouse Here is my local script:

script.Parent.MouseButton1Click:Connect(function(player)
local House = game.Workspace.player.Name.."'sHouse"--keep getting error here
end)

New error Players.theking66hayday.PlayerGui.SettingPopup.Frame.TextButton.Script:4: attempt to index nil with 'Name' This time I am using a normal script in a button ui

local Players = game:GetService('Players')
local Player = Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
local House = workspace:FindFirstChild(Player.Name.."'sHouse")
game.Workspace[Player.Name.."'sHouse"].DoorWorking.Door.DoorI.ProximityPrompt.ScriptB = true

3 answers

Log in to vote
0
Answered by 1 year ago

Hey there, could you try doing this instead?

script.Parent.MouseButton1Click:Connect(function(player)
    local House = game.Workspace[player.Name .. "'sHouse"]
end)

I suggest printing out the result to really know what's going on.

0
I keep getting this error now Players.theking66hayday.PlayerGui.SettingPopup.Frame.TextButton.LocalScript:2: attempt to index nil with 'Name' theking66hayday 841 — 1y
0
Ah, perhaps the "player" argument gives you the name already and no need for the .Name. Anyways, I'm glad you found a solution to your issue! Mafincho 43 — 1y
0
Sadly it just stopped working the solution I edited my post theking66hayday 841 — 1y
0
What do you mean by a normal script? I believe you can only access the LocalPlayer through a Local Script Mafincho 43 — 1y
View all comments (2 more)
0
Ok, I did already tried through a local script but still same error theking66hayday 841 — 1y
0
Ah, I believe I get it. Perhaps try defining the player inside the function? Mafincho 43 — 1y
Ad
Log in to vote
0
Answered by
pwx 1581 Moderation Voter
1 year ago
local Players = game:GetService('Players')
local Player = Players.LocalPlayer

script.Parent.mouseButton1Click:Connect(function()
    local House = workspace:FindFirstChild(Player.Name.."'s House")
    if House then
        -- do stuff here
    end
end)
0
It stopped working I updated my answer with the new script theking66hayday 841 — 1y
Log in to vote
0
Answered by 1 year ago

Found answer can't disable scripts in local script also I finally solved the player issue too

Answer this question