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?
local UpgradePart = script.Parent UpgradePart.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then local player = hit.Parent.Parent player.PlayerGui.UpgradesShop.MainFrame.Visible = true else return nil end end)
Try this:
local UpgradePart = script.Parent UpgradePart.Touched:Connect(function(hit) local Player = game.Players:GetPlayerFromCharacter(hit.Parent) if Player then Player.PlayerGui.UpgradesShop.MainFrame.Visible = true end end)
PlayerGui is not inside of the character!
try getting the player
local player = game.Players:GetPlayerFromCharacter(hit.Parent.Parent)
You're referencing the player's character, not player, do
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)