This script makes it so if you Hit the part that it would open up a certain GUI depending on how much of a certain leaderstats you have (Coins).
But I get this error.
local part = script.Parent
part.Touched:Connect(function(hit)
local plr = hit.Parent:FindFirstChild('Humanoid')
if hit.Parent:FindFirstChild('Humanoid')and plr.leaderstats.Coins.Value <= 100 then
plr.PlayerGui.HaveCoins.Visible = true
elseif hit.Parent:FindFirstChild('Humanoid')and plr.leaderstats.Coins.Value >= 100 then
plr.PlayerGui.NotHaveCoins.Visible = true
end
end)
Where are your leaderstats located - in the player Model or within the Players service? With the assumption that your leaderstats are found within the Player Object (of Players service) then use this function:
local player = Players:GetPlayerFromCharacter(part.Parent)
You’re trying to retrieve leaderstats from your humanoid. That isn’t how it works. Since it’s located in the player, you must get the player from the character model. So, do this: local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
local part = script.Parent
part.Touched:Connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if hit.Parent:FindFirstChild('Humanoid')and plr.leaderstats.Coins.Value <= 100 then
plr.PlayerGui.HaveCoins.Visible = true
elseif hit.Parent:FindFirstChild('Humanoid')and plr.leaderstats.Coins.Value >= 100 then
plr.PlayerGui.NotHaveCoins.Visible = true
end
end)
Maybe you forgot to name the ScreenGui, if there is one
local part = script.Parent
part.Touched:Connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if not plr then return end
local Screen = plr.PlayerGui[""] -- ScreenGui name
if plr.leaderstats.Coins.Value <= 100 then
Screen.HaveCoins.Visible = true
elseif plr.leaderstats.Coins.Value >= 100 then
Screen.NotHaveCoins.Visible = true
end
end)
So this script works.But it gives up the same message no matter how many coins you have.
local part = script.Parent
part.Touched:Connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if not plr then return end
local Screen = plr.PlayerGui["TeleporterGUI"] -- ScreenGui name
if plr.leaderstats.Coins.Value < 100 then
Screen.NotHaveCoins.Visible = true
elseif plr.leaderstats.Coins.Value >= 100 then
Screen.HaveCoins.Visible = true
end
end)
P.S. So I have like a 1,400 coins and I change it to 99 and I wonder if it didn’t register.
Ok with a little bit of print magic apparently it didn’t register.