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

FilteringEnabled Code Runs Multiple Times Time When It Should Run Once?

Asked by
INOOBE_YT 387 Moderation Voter
7 years ago

So, I have made a FilteringEnabled walkspeed boost pad. When touched, instead of the person who touched it gets the boost, everyone in the server gets it and it runs once per person in the server. Is there any way to make it run once and for the person who touched the part?

--Server script
local Button = script.Parent.Button
local Event = game.ReplicatedStorage["Remote Events"]["Bonus_Walkspeed_Pad"]
local Duration = 3
local Boost = 2


Event.OnServerEvent:connect(function(Player)
    local Character = Player.Character
    local Humanoid = Character:FindFirstChild("Humanoid")
    Button.CFrame = Button.CFrame * CFrame.new(0, -0.1, 0)
    Button.BrickColor = BrickColor.new("Dark stone grey")
    Humanoid.WalkSpeed = Humanoid.WalkSpeed * Boost
    wait(Duration)
    Button.CFrame = Button.CFrame * CFrame.new(0, 0.1, 0)
    Button.BrickColor = BrickColor.new("Bright green")
    Humanoid.WalkSpeed = Humanoid.WalkSpeed / Boost
end)
--Local script
local RemoteEventFolder = game.ReplicatedStorage:WaitForChild("Remote Events")
local RemoteEvent = RemoteEventFolder["Bonus_Walkspeed_Pad"]
local Model = game.Workspace["Button FilteringEnabled"]
local Enabled = true

Model:FindFirstChild("Button").Touched:connect(function(Hit)
    if Hit.Parent and Hit.Parent:FindFirstChild("Humanoid") and game.Players:FindFirstChild(Hit.Parent.Name) and Hit.Parent:FindFirstChild("Humanoid").Health > 0 then
        if Enabled == true then
            Enabled = false
            RemoteEvent:FireServer()
            wait(4)
            Enabled = true
        else
            print("Already Fired, waiting for cooldown.")
        end
    end
end)
0
Nothing about this seems incorrect to me. Can you provide a ROBLOX Place we can enter in Edit Mode to see what might be causing this? adark 5487 — 7y
0
Here is the uncopylocked model in-game. https://www.roblox.com/games/684260392/Testing INOOBE_YT 387 — 7y

2 answers

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

Your local scripts are checking to see if any player is touching the brick, instead of just the LocalPlayer. Then, regardless of which player they found, they tell the server "Activate for my player please" (as the LocalPlayer is always sent as the first argument to RemoteEvents/Functions). The server has no debounce, and so doesn't mind giving more than one person a boost.

You should merge the scripts into a single Script (on the server), removing all references to the RemoteEvent (where you normally call the RemoteEvent, just call the function responsible for boosting a player). There needn't be any client/LocalScript interaction here, since Touched events fire on the server as well.

Ad
Log in to vote
0
Answered by 5 years ago

Yes there is, Try using Firing a client only for the player,which raises the walkspeed.

0
This was answered a year ag0 INOOBE_YT 387 — 5y
0
oh sorry. Wait ae you a scripter? in that case you can help me with a few of my scripts Danielp533 16 — 5y

Answer this question