My touched event is supposed to open a gui. At first it opened for everyone when its supposed to open only for the player who touched it. So I edited it and now its broken. Whats wrong?
01 | local UpgradePart = script.Parent |
02 |
03 | UpgradePart.Touched:Connect( function (hit) |
04 | if hit.Parent:FindFirstChild( "Humanoid" ) then |
05 | local player = hit.Parent.Parent |
06 | player.PlayerGui.UpgradesShop.MainFrame.Visible = true |
07 | else |
08 | return nil |
09 | end |
10 | end ) |
Try this:
1 | local UpgradePart = script.Parent |
2 |
3 | UpgradePart.Touched:Connect( function (hit) |
4 | local Player = game.Players:GetPlayerFromCharacter(hit.Parent) |
5 | if Player then |
6 | Player.PlayerGui.UpgradesShop.MainFrame.Visible = true |
7 | end |
8 | end ) |
PlayerGui is not inside of the character!
try getting the player
1 | local player = game.Players:GetPlayerFromCharacter(hit.Parent.Parent) |
You're referencing the player's character, not player, do
1 | local Player = game.Players:GetPlayerFromCharacter(hit.Parent) |