So bassicly debounce is being completely ignored in my code and the function is being ran multiple times, the code is simple, it clones a script and adds it to the character. without debounce it was making multiple clones of the same script and putting inside, normally I wouldn’t much care but this has been causing alot of lag.
No the function is meant to be ran only once in a life time, so I didn’t change debounce back to false.
The script is cloning a other scripts and adding to the character, essentially im making a morph and that script clones the abilities of the morph. for example, if a character can fly then it’ll clone the fly script
Oh another idea for running the code only once. Didn’t test it yet and sorry for the formatting.
local touchedByPlayer = false
while not touchedByPlayer do
local hit = script.Parent.Touched:Wait()
if hit is touched by player then
touchedByPlayer = true
end
end
I didn’t try the other 2 options because im a novice to scripting(im getting help from my friend with my scripts like fly and advanced things and yes I already asked him about it and he didnt know what was wrong), but “hit is touched by player” is registering as invalid. Is that what you mean by formatting?
local DB = false
script.Parent.Touched:Connect(function(hit)
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
if Player and not DB then
DB = true
local Character = hit.Parent
--Do your stuff here
end
end)
Oh that was psuedo code “hit is touched by player” it’s not real code, it’s supposed to represent what you did with the if statement you wrote.
local touchedByPlayer = false
while not touchedByPlayer do
local hit = script.Parent.Touched:Wait()
local player = Players:GetPlayerFromCharacter(hit.Parent)
if player then
touchedByPlayer = true
--other code is here that you didn't post
end
end
Also I see there is a typo, the screen shot did
Players:GetPlayerFromCharacter(part.Parent)
--however it shuld be
Players:GetPlayerFromCharacter(hit.Parent) -- get the players player
This might have caused the error, not sure what part.Parent is.
Part.Parent would be the player when he hits the part I think, not sure tho.
that didn’t work, starting to suspect it something on one of the scripts my friend made, either way keep posting ideas if you come up with any more, hopefully one of them will save my day.