When player remove,their tycoon does not destroy

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

end)

Supplementary Note
i use tycoon kit:Tycoon Model (Watch Video) - Roblox

Another question

if tycoon deposition on workspace,save player data how to implement(ex: gamer m8 method become B Ricey’ method)

thanks!

1 Like

Please check this in a live game, as I believe that this event won’t work in Studio. You can also check with a 2 player Test Server.

1 Like

i try it ,but no destroy tycoon




What’s inside of the ReplicatedStorage?

I need a Precision.

This topic should be on #help-and-feedback:scripting-support instead of #help-and-feedback:platform-usage-support.

I think it must be destroying 1 part per second, change wait(1) to wait() to see if this is the problem

sorry i first post,already edited
122

Are you positive that your script is getting to the PlayerRemoved event in the first place?

i try it , but not valid(destroy)

How are you storing the OwnerValue? If you’re storing a string with the player’s name, then you’d want to do:

if v.TycoonModel.Values.OwnerValue.Value == Player.Name then

Instead of:

if v.TycoonModel.Values.OwnerValue.Value == Player then
1 Like

i revise it,but no success to destroy tycoon

Supplementary Note

i use tycoon kit

Make sure you clone it first!

local TycoonClone = game.ReplicatedStorage:FindFirstChild(v.Name):Clone()
1 Like

Keep it as Player, not Player.Name. Looking at how the tycoon is set up it is an object value

1 Like

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)
1 Like

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)

end)

im pretty sure it is that, have you checked yet?

xue hue hao piao piao bing chilling

Can you do this, in-a-script, please?

Like this:


bandicam 2022-12-09 15-53-29-412

Sorry, what does this mean, I can’t see it from the picture

bandicam 2022-12-09 15-53-29-412 = bandicam 2022-12-10 13-32-28-497, To be exact, it’s right here:
bandicam 2022-12-10 13-34-45-030