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

How do I access game.Players.LocalPlayer in a standard script?

Asked by
AZDev 590 Moderation Voter
9 years ago

I need to access the player that clicks a block block. I also need to access the player who's mouse hovers over a block. My code only works in studio.

workspace.ChangeOutfit.ClickDetector.MouseClick:connect(function(changeOutfit)
    local pz=game.Players.LocalPlayer.Character:GetChildren() 
    for i=1,#pz do 
    if pz[i].className=="Shirt" then 
    pz[i]:Destroy() 
    end 
    end
    local shirt = Instance.new("Shirt")
    shirt.Parent = game.Players.LocalPlayer.Character
    shirt.Name = "NewOutfit"
    shirt.ShirtTemplate = "http://www.roblox.com/asset/?id=332017894"
end)

This works in studio but not on a game server.

script.Parent.Parent.ClickDetector.MouseHoverEnter:connect(function(ShowClothingGui)
    Gui = script.Parent.Clothing:Clone()
        Gui.Parent = game.Players.LocalPlayer.PlayerGui
end)

script.Parent.Parent.ClickDetector.MouseHoverLeave:connect(function(HideClothingGui)
    Gui:Destroy()
end)

The same with this code.

Thanks for your help.

2 answers

Log in to vote
1
Answered by 9 years ago
workspace.ChangeOutfit.ClickDetector.MouseClick:connect(function(player) -- has a parameter pre-set to return player as a parameter
    local pz=player.Character:GetChildren()
    for i=1,#pz do 
    if pz[i].className=="Shirt" then 
    pz[i]:Destroy() 
    end 
    end
    local shirt = Instance.new("Shirt")
    shirt.Parent = player.Character -- Edited to change this didnt see it sry .-.
    shirt.Name = "NewOutfit"
    shirt.ShirtTemplate = "http://www.roblox.com/asset/?id=332017894"
end)

http://wiki.roblox.com/index.php?title=API:Class/ClickDetector

Ad
Log in to vote
-1
Answered by
Scriptecx 124
9 years ago

You can't access the Client from the server, However, but you can get the player that clicked the ClickDetector because it takes a parameter for the player.

Answer this question