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