Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to make this script be more responsive?

##Code Information

I have a script that has a Touched event. The variable, speedPad, is listening to the touched event. I used an array called touchedSpeedPad to store all the character's names that have touched the speedPad. This made the SpeedPad more responsive, however, this doesn't prevent the lag occurring. Is there any way to hide and/or stop this lag from happening to the players.

##Some Other Important Stuff

####Please don't say to do debounce because debounce makes the players go one by one!

####Also, please don't say to use Part:GetTouchingParts() because the character's parts are CanCollide false

####People also say that I should handle this code on the client side. I don't think this is a good idea, however, I probably might be wrong. Should I listen to them?

Edit: Plus, the character's parts have no TouchInterest in them

##Code

local speedPad = script.Parent
local duration = jumpPad:WaitForChild("Duration")
local speed = jumpPad:WaitForChild("Speed")

local touchedSpeedPad = {}

local function onTouched(hit)
	local humanoid = hit.Parent:FindFirstChild("Humanoid")
	if humanoid then
		local char = hit.Parent	
		if touchedSpeedPad[char.Name] then return end		
		
		touchedSpeedPad[char.Name] = true		
		humanoid.WalkSpeed = speed.Value
		
		wait(duration.Value)
		humanoid.WalkSpeed = 20
		touchedJumpPad[char.Name] = nil
	end
end

jumpPad.Touched:Connect(onTouched)

8 comments

0

Parts with CanCollide set to false still fire touched events.

0

I am not talking about the Touched event. Please read: "...don't say to use Part:GetTouchingParts() because the character's parts are CanCollide false". As you can see, I am not referring to Part:GetTouchingParts(), not Instance.Touched

0

Still, the method still gets parts that are CanCollide = false.

0

This is the exact description of Part:GetTouchingParts(), "Returns a table of all CanCollide true parts that intersect with this part. If the part itself is CanCollide false, then this function will return an empty table UNLESS it has a TouchInterest." Source: http://robloxdev.com/api-reference/function/BasePart/GetTouchingParts

0

Where do you think the lag is stemming from?

0

I feel like the lag is input lag and/or latency lag.

0

I mean if it's latency lag, only real way to resolve it is by making this client-side. I agree that that's not probably the way to go. A way to counteract this lag is to maybe include an animation of some sort, client-side, so that it appears like the response time is more immediate. Sort of like revving up a toy car before letting it go.

0

When I make this client side, it seems to break much more than what I would do on Server Side

1 answer

Well you don't have any wait() in the Script so it should run the Script instantly it might be just a problem with the Studio trying to run the Script a slight delay between the character touching the pad and then the script noticing it's been touched.

2 comments

0

I am not testing in studio, I am testing in-game

0

Then it must be a problem with the Game and the Server communcating.

This discussion is preserved as it was. New answers, comments, and votes are closed.