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

How to get the player from :MouseButton1Click()?

Asked by
lucas4114 607 Moderation Voter
9 years ago

So, I'm making a script and I made a function that is called by :MouseButton1Click() so in the function I made the parameters "plr" and in the function I made this line "if plr.Parent.Parent.PlayerHasBase.Value == false then" and it doesn't work, because the output says plr = nil so then I need help, how do I get the player from a click? Because my way doesn't work.... :c Full script:

function SpawnBase(plr)
    if plr.Parent.Parent.PlayerHasBase.Value == false then
        local Base = game.ServerStorage.Base:Clone()
        Base.Parent = plr.Character
        Base:MoveTo(game.Workspace.Spawn1.Position)
    end
end

script.Parent.MouseButton1Click:connect(SpawnBase)
0
If possible, use a LocalScript and define plr as game.Players.LocalPlayer Tempestatem 884 — 9y
0
It says in the output "19:37:25.263 - PlayerHasBase is not a valid member of DataModel" If I do that.... lucas4114 607 — 9y
0
If it is a local script then player.Parent.Parent is "game" BSIncorporated 640 — 9y
1
Tempestatem is right, idk what you are searching for, 3 layers above the player, that doesn't make sense, can you elaborate a bit more what PlayerHasBase is and where it is located? dragonkeeper467 453 — 9y
View all comments (4 more)
0
Oh, forgot to change that when I used LocalPlayer..... lucas4114 607 — 9y
0
Did that fix your problem lucas4114? magiccube3 115 — 9y
0
Yup..... lucas4114 607 — 9y
0
bruh just use local plr = game.Players.LocalPlayer MiuGaming67 0 — 3y

Answer this question