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

Is it possible to make this script touch function faster in a normal server?

Asked by 7 years ago
Edited 7 years ago

Quick question, is it possible to make this script function faster in a normal server? In Roblox Studio it functions properly, but when I join a server this script waits like 0.5 and then anchors the part. I need it to anchor the part right away with no waits. Is this possible? Note: Parts are raining and they stack on top of each other, but the onTouched is slow, so they anchor late. Thanks!

function onTouched(hit)
    if hit.Anchored == true then
        script.Parent.Anchor = true
    end
end

script.Parent.Touched:connect(onTouched)
0
Maybe use a direct function? Like script.Parent.Touched:connect(function(hit) end) xuefei123 214 — 7y
0
Thanks for suggesting this, but it still functions slow. GatitosMansion 187 — 7y
0
use client Zyrup 27 — 7y
0
xuefei123: of course that makes no difference at all. they mean exactly the same thing. BlueTaslem 18071 — 7y
0
make it work with the client EssentialRoll 30 — 7y

1 answer

Log in to vote
1
Answered by
Zyrup 27
7 years ago
Edited 7 years ago

ROBLOX Studio is a server simulated on a client, it's confusing, but don't worry. We can use the client to detect when the brick has been touched, you haven't provided context, though. I'm doing it in the case as if you're waiting for a player to step on it (This will still work if you're trying to use some sort of raining parts, but this script would be less efficient for that, I suggest putting a debounce on the server instead).

Server script, this could either go in Workspace or ServerScriptService.

local network = Instance.new("RemoteEvent", game.ReplicatedStorage)

network.OnServerEvent:connect(function(player, part)
    part.Anchored = true
end)

Client script, this could either go in LocalPlayer, PlayerGui, StarterPack or StarterPlayerScripts.

local network = game.ReplicatedStorage:WaitForChild("RemoteEvent")

local debounce = false

workspace.Part.Touched:connect(function(hit)
    if debounce == false then
        debounce = true
        --if hit.Parent:FindFirstChild("Humanoid") then --Optional
            network:FireServer(workspace.Part)
        --end
        wait(0.5)
        debounce = false
    end
end)

As I said I'm doing it in the sense that you want a player to touch the brick, not what I think you're trying to do (Raining parts that anchor on floor hit).

0
Sorry, I did not mention that players have nothing to do with it. The raining parts have to anchor on top of each other. The onTouched script is located in each part. Thanks for you answer though! I upvoted. GatitosMansion 187 — 7y
Ad

Answer this question