When I try to move my coin to a folder for inactive coins (coins that already have been collected in this round and will be restored in the next round) by setting the Parent property, it seems to get a little confused. I want to refer to the Parent of the script by using script.Parent, but also wanna set the Parent property of that instance by using .Parent = after. Any help would be appreciated!
local originalparent = script.Parent
local coins = game:GetService('Workspace').CoinsCollected
local coinsfolder = game:GetService('ReplicatedStorage').InactiveCoins
local restart = game:GetService('ReplicatedStorage').Restart
script.Parent.Touched:Connect(function(part)
if part.Parent:FindFirstChildOfClass('Humanoid') then
coins.Value += 1
script.Parent.Parent = coinsfolder
end
end)
restart.OnServerEvent:Connect(function()
script.Parent.Parent = originalparent
end)
Only have one script, in ServerScriptService, that handles the coin pickup, this will make the game less laggy. Something like
local coinsFolder = game.Workspace.Map.Coins:GetChildren()
local inactiveCoins = game.Workspace.Map.InactiveCoins:GetChildren()
for _, coin in pairs(coinsFolder) do
if not coin:IsA("BasePart") then continue end
coin.Touched.Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
-- Add coins
coin.Parent = inactiveCoins
end
end
end
Yes! Try it yourself by making two folders, inserting a part into one of them, then inserting a script that tries to move the part to the other folder that way, run it, and you’ll see the instance dissapears.
I think its really stupid to keep saying that “try my suggestion” you need to wait for your turn. Ok? and @iamajust it works for me try using a separate script