Okay, let me try. I had similar thing earlier, which didn’t work.
The script I just provided you doesn’t cause any lag. I’ve just ran a test, so I am unsure what you’re on about…
https://i.gyazo.com/eff039d6d9f83cfd1200dc20d5acf5bd.mp4
I’m having thousands of those and 24 players.
So add a wait() statement, plus it only checks if it is the local player, it doesn’t do this for every player? So the player count shound’t matter.
Didn’t work. I don’t know why.
Have you tried my solution yet? Before you assume there is lag, you should check.
If this does cause lag, could you send a GIF of it lagging?
I had it until now, made test session and players complaining about having lags.
Try moving the wait() statement to the touch event;
local Player = game.Players.LocalPlayer
for _, Part in pairs(workspace.Colorables:GetChildren()) do
Part.Touched:Connect(function(hit)
wait(.5)
if hit.ClassName == "Meshpart" and hit.Name == "LeftFoot" or hit.Name == "RightFoot" then --for example
if hit.Parent == Player.Character then
Part.Color = hit.Color
end
end
end)
end
I also recommend putting this script in StarterGui, I do not know where you have it located but you should place this script in StarterPack or StarterGui.
If this still does not work, have a serverside script controlling when the script works, you could delete it from the Backpack or PlayerGui and clone and add it when ENTER is touched, and then when EXIT is touched it destroys it to prevent even more lag.
I don’t want it random and it didn’t work, but thanks.
Thanks I get you, but I’d still rather do it with the Character. But thanks.
It’s going to be a lot better to check collisions on the players character. That way you will only have 2*players connections active instead of thousands.
Exactly, but now, how to do it?
Good luck with finding a solution, hope I helped.
Try putting this in starterCharacter
local feet
if script.Parent.Humanoid.RigType == "R15" then
feet = {script.Parent:WaitForChild("RightFoot"),script.Parent:WaitForChild("LeftFoot")}
else
feet = {script.Parent:WaitForChild("Right Leg"),script.Parent:WaitForChild("Left Leg")}
end
local function onTouch(hit)
if hit.Name == "Colorable" then
--Color things here
print("Coloring")
end
end
feet[1].Touched:Connect(onTouch)
feet[2].Touched:Connect(onTouch)
Thanks, I’ll test it, is there any other way adding more parts of Character?
Do you suggest adding a debounce in this case or not? I was reading through the post and was not sure if the cause of the lag could have been from not having a debounce or something else.
An example of a debounce. Maybe this could stop the lag. Try it out @sebi210
local Player = game.Players.LocalPlayer
local Debounce = false
for _, Part in pairs(workspace.Colorables:GetChildren()) do
Part.Touched:Connect(function(hit)
if not Debounce then
Debounce = true
if hit.ClassName == "Meshpart" and hit.Name == "LeftFoot" or hit.Name == "RightFoot" then --for example
if hit.Parent == Player.Character then
Part.Color = hit.Color
end
end
wait(5) --how long before the touched can be activated again
Debounce = false
end
end)
end
I’m not sure what you mean by that, could you elaborate?
If the player touches with Arm, for example? Then to color it too?
Because it’s being calculated on the player which can only turn it one color, a debounce isn’t necessary. If the color changed each time it was touched, then it would flash really quickly without it.
I understand what you’re saying but would you think a debounce is necessary for the purposes of not creating thousands of Touched events each second?