I’m trying to change a model’s parent based on a leaderstat’s value but when i play the script doesn’t change it’s parent.
this is what i tried
if game.Players.LocalPlayer.Roomitems.Spot1.Value==2 then
script.Parent.Parent=game.Workspace
I’m trying to change a model’s parent based on a leaderstat’s value but when i play the script doesn’t change it’s parent.
this is what i tried
if game.Players.LocalPlayer.Roomitems.Spot1.Value==2 then
script.Parent.Parent=game.Workspace
It is because you don’t reference the leaderstats
if game.Players.LocalPlayer.leaderstats.Roomitems.Spot1.Value==2 then
script.Parent.Parent=game.Workspace
End
I’d recommend creating variables before you do actually start creating your if statement
so that it’s easier to read & good practice:
local Player = game.Players.LocalPlayer
local leaderstats = Player:WaitForChild("leaderstats")
if leaderstats.Roomitems.Spot1.Value == 2 then
script.Parent.Parent = workspace
end
You have to fire it when it changed!!!
It only fires on enter, which won’t work when the value changes!
This is the fixed script:
local player = game:GetService(“Players”).LocalPlayer
local Value = player:WaitForChild(“Roomitems”).Spot1local Model = script.Parent.Parent
Value.Changed:Connect(function()
if Value.Value == 2 then
Model.Parent = workspace
end
end)
Let me know if something doesn’t work!