Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to make this script be more responsive?

Asked by 5 years ago
Edited 5 years ago

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)
0
Parts with CanCollide set to false still fire touched events. User#19524 175 — 5y
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 saSlol2436 716 — 5y
0
Still, the method still gets parts that are CanCollide = false. User#19524 175 — 5y
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 saSlol2436 716 — 5y
View all comments (4 more)
0
Where do you think the lag is stemming from? ScrewDeath 153 — 5y
0
I feel like the lag is input lag and/or latency lag. saSlol2436 716 — 5y
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. ScrewDeath 153 — 5y
0
When I make this client side, it seems to break much more than what I would do on Server Side saSlol2436 716 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

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.

0
I am not testing in studio, I am testing in-game saSlol2436 716 — 5y
0
Then it must be a problem with the Game and the Server communcating. Cryo_Dev 9 — 5y
Ad

Answer this question