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

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

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)

5 comments

0

Maybe use a direct function? Like script.Parent.Touched:connect(function(hit) end)

0

Thanks for suggesting this, but it still functions slow.

0

use client

0

xuefei123: of course that makes no difference at all. they mean exactly the same thing.

0

make it work with the client

1 answer

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).

1 comment

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.

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