Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

Why is the script only being disabled in the client and not the server?

Asked by 2 days ago
Edited 2 days ago

So I'm making a ban hammer that actually bans the player (not really, it's just a kick with a silly message and some creepy music plays inside their head so only they can hear it) but that's not the issue. So I wanted the player to be able to toggle kicking others or not. So, when the player equips the hammer, there is a ban Gui that lets you turn it on and off. Here is the local script:

local lp = game.Players.LocalPlayer
local lpc = lp.Character
local ON = script.Parent.BanModeToggle.ON
local OFF = script.Parent.BanModeToggle.OFF
local l = ON.Parent.BanLabel
ON.MouseButton1Click:Connect(function()
    if lpc.BanHammer ~= nil then
        lpc.BanHammer.Handle.KickRadius.Kick.Disabled = false
        l.Text = "Ban Mode: ON"
    end
end)
OFF.MouseButton1Click:Connect(function()
    if lpc.BanHammer ~= nil then
        lpc.BanHammer.Handle.KickRadius.Kick.Disabled = true
        l.Text = "Ban Mode: OFF"
    end
end)

When viewing on the client, the script disables. But when viewing on the server, the script stays enabled. How can I make the script actually disable? (also, no there is nothing wrong with the kicking script, I've tested it a million times) EDIT: I should also clarify, the text is changing on the script that disables and enables the script plus no errors in the output.

0
Its obvious. local script runs in the client, normal script in the server. You cannot disable a script with a localscript, try with a script! I hope i was able to help! good day! TheEagle722 99 — 2d
0
Due to Filtering Enabled, you CANNOT do what you're trying to portray unless with a remote event or a serverscript. Gui's are only accessible with a local script! JesseSong 3389 — 2d

1 answer

Log in to vote
0
Answered by 2 days ago
Edited 2 days ago

This is because you're only disabling it on the Clients side, this is where a RemoteEvent will come in so we can communicate from Client to Server.

So first, let's make a RemoteEvent in ReplicatedStorage and call it Toggle

Secondly, in the TextButton we'll have a LocalScript that will fire the Event with the following:

local RP = game:GetService("ReplicatedStorage")
local Event = RP:WaitForChild("Toggle") -- name of the RemoteEvent
local on = true

script.Parent.MouseButton1Click:Connect(function()
    if on == true then
        on = false
        script.Parent.Text = "Turned off BanHammer"
    else
        on = true
        script.Parent.Text = "Turned on BanHammer"
    end
    Event:FireServer()
end)

Finally, we want a Script in ServerScriptService to respond to the Event being fired with the following:

local RP = game:GetService("ReplicatedStorage")
local Event = RP:FindFirstChild("Toggle")

Event.OnServerEvent:Connect(function(player)
    local character = player.Character
    local backpack = player.Backpack

    if character:FindFirstChild("BanHammer") then --Checks character to see if they're equipping it
        local Tool = character:FindFirstChild("BanHammer")
        if not Tool.Script.Disabled then
            Tool.Script.Disabled = true
        else
            Tool.Script.Disabled = false
        end
    elseif backpack:FindFirstChild("BanHammer") then --checks backpack to see if they're not equipping it
        local Tool = backpack:FindFirstChild("BanHammer")
        if not Tool.Script.Disabled then
            Tool.Script.Disabled = true
        else
            Tool.Script.Disabled = false
        end
    end
end)

Hopefully, this helps : )

Note: I suggest doing some research on RemoteEvents because they are pretty important.

0
You have some deprecated/outdated practices like :Connect not :connect! JesseSong 3389 — 2d
0
force of habit, will edit it right now AntoninFearless 538 — 2d
Ad

Answer this question