when player remove tycoon ,their tycoon not implement destroy,I’m not sure what I did wrong here
script
game.Players.PlayerRemoving:Connect(function(Player)
local TycoonFolder = game.Workspace.Tycoons
for i,v in pairs(TycoonFolder:GetChildren()) do
if v.TycoonModel.Values.OwnerValue.Value == Player then
local TycoonClone = game.ReplicatedStorage:FindFirstChild(v.Name)
v:Destroy()
wait(1)
TycoonClone.Parent = TycoonFolder
end
end
Ok yeah the kit you are using is absolutely terrible, lots of errors in it and limited functionality. However, if you wish to keep using it, use this code for the deletion instead - I have fixed a couple of the errors in it:
game.Players.PlayerRemoving:Connect(function(Player)
local TycoonFolder = game.Workspace.Tycoons
for i,v in pairs(TycoonFolder:GetChildren()) do
if v.Values.OwnerValue.Value == Player then
local TycoonClone = game.ReplicatedStorage:FindFirstChild(v.Name):Clone()
v:Destroy()
wait()
TycoonClone.Parent = TycoonFolder
end
end
end)
Thank you. Although it still doesn’t work after I update, but when I open a new file. It success. so the question is the order of remove. I need to think about how to change it.
I am thinking whether it is the 〈remove〉 problem in cash script
when i use cash script , tycoon is not destroy
local ds = game:GetService(“DataStoreService”):GetDataStore(“TutorialData”) –
–// Functions
game.Players.PlayerAdded:Connect(function(plr) – On player enter
local Prefix = plr.UserId – Quick access to the Users ID.
local leaderstats = Instance.new("Folder", plr) -- Creates a new folder for the Cash to go in. the 2nd parameter is for the Parent.
leaderstats.Name = "leaderstats" -- Names it
local Cash = Instance.new("IntValue", leaderstats) -- Creates a IntValue for Cash.
Cash.Name = "Cash" -- Names it
local CashData = nil -- To grab the data of the value we'll store the value into this variable.
pcall(function()
CashData = ds:GetAsync(Prefix) -- Sets the Variable to the Value saved or makes it nil for a new player.
end)
if CashData ~= nil then -- If the user does have data then we can load it into the Cash.
Cash.Value = CashData
else
Cash.Value = 0 -- Else if CashData == nil then creates a new amount for the player. aka as the Start value
end
end)
game.Players.PlayerRemoving:Connect(function(plr) – On player leave
local Prefix = plr.UserId – Quick access to the Users ID.
local Cash = plr.leaderstats.Cash -- Locates the Players cash.
pcall(function()
ds:SetAsync(Prefix, Cash.Value) -- Saves it.
end)