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

How do i make this gui show to only the player that touched the part instead of everyone?

Asked by 3 years ago

So my problem is that this GUI shows for everybody This is the script that shows the GUI

game.Workspace.ShopPart.Touched:Connect(function(hit)
    if hit then
        script.Parent.Shop.Frame.Visible = true
    end
end)

I tried everything I knew but it didn't work out. Does anyone know what can I do with this code to fix it?

2 answers

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago
game.Workspace.ShopPart.Touched:Connect(function(hit)
    if hit:IsA("BasePart") then -- checking if hit isnt accessory or something like that
        if hit.Parent:FindFirstChild("Humanoid") then -- if we can find Humanoid inside hit.Parent if yes, then hit.Parent is player

    local player = game.Players:GetPlayerFromCharacter(hit.Parent) -- hit can be Arm, Head, Torso so we want Parent of that which is player

                player.PlayerGui.Shop.Frame.Visible = true -- you need to put that gui inside StarterGui

        end
    end
end)
0
Thank you so much! I really appreciate the explanation too! kapkap27 2 — 3y
Ad
Log in to vote
0
Answered by 3 years ago
 script.Parent.Shop.Frame.Visible=game.Players.LocalPlayer.Name==hit.Parent.Name

Answer this question