bro wth are you even saying? are you trying to set the parent property of the parent of the script?
Yes, that’s what I’m trying to do.
then just do
script.Parent.Parent = -- path to the new parent
I know that’s what you think is the correct way to do it, I tried that too, but it doesn’t work. It just deletes the instance.
are you even setting what it should be?
Have you tried my suggestion?
Chars
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
I will try, but do you recommend also setting health to 0 and handling tweens for all coins this way? (Setting health to 0 is for traps.)
If their in a script in the coins right now, then yes change that.
I don’t get what you mean by this.
he means humanoid health
Well, your parenting thing might work, I cant try since I’m on mobile, however it’s not good to have a script in every single coin anyways
Yes however if he sets the Humanoid.Health to 0 they would die, which why would they die when they collect a coin?
Why do I have to add characters to a post referencing another post as a response? Anyway, I just beat the character limit by asking myself deep questions about it.
Oh sorry I didn’t see that part, I’m either blind or it didn’t load.
You can select a random coin like maybe try this script:
local coinsFolder = game.Workspace.Map.Coins:GetChildren()
local inactiveCoins = game.Workspace.Map.InactiveCoins:GetChildren()
for i=1,#coinsFolder do
local coin = coinsFolder[i]
if not coin:IsA("BasePart") then continue end
coin.Touched.Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
if i % 4 == 0 then
player.Character.Humanoid.Health = 0
else
-- Add coins
end
coin.Parent = inactiveCoins
end
end
end
Explenation:
- Get variables for the folder
- Loop through using for i=1 loop
- Get the coin using coinsFolder[i]
- Set up a touch event
- Make sure a player hit the part
- Check if the remainder of i/4 == 0
- Decide to add coins or to kill player
I’m so confused right now. I just tested it in a fresh new baseplate instead of my actual game and it works. I don’t understand why it’s acting differently on my game.
Update: I got it working. I don’t know what I did wrong first, but instead a new part of the script is not working. I’m talking about this:
local originalparent = script.Parent
restart.OnServerEvent:Connect(function()
script.Parent.Parent = originalparent
end)
Other things happen in between these two parts (you can see the full script in the original post), but the originalparent variable is set at the beginning of the script, before moving it to the inactive folder.
I have switched all coin management to one script by suggestion of @domboss37. I have limited this to only coin management as different traps have different specific executions. I would also like to apologize to @Qinrir for all the confusion. I don’t know what was causing it to not work only in my specific game I’m working on, but it has now been fixed. Thank you all for contributing to a great solution!