Not entirely sure where you’re getting that information from. tool.Equipped works in both Server and Local scripts. I think the issue here is that if the script in question here is a LocalScript, disabling a script will not work, as any changes a client makes to anything outside of the character directly will not replicate to the server, and thus, will have no effect.
If you want to disable the script from a LocalScript, you will have to tie it to a RemoteEvent, picked up by a separate ServerScript in the tool which will then disable/enable the script in question when the events are handled. For example.
--[[
Layout of tool:
Tool
Events - Folder
DisableEvent - RemoteEvent
PunchScript
DisableClient - LocalScript
DisableServer - ServerScript
]]--
-- DisableClient
local Tool = script.Parent
local Events = Tool.Events
local DisableEvent = Events.DisableEvent
Tool.Equipped:Connect(function()
DisableEvent:FireServer(true)
end)
Tool.Unequipped:Connect(function()
DisableEvent:FireServer(false)
end)
-- DisableServer
local Tool = script.Parent
local Events = Tool.Events
local DisableEvent = Events.DisableEvent
local PunchScript = Tool.PunchScript
DisableEvent.OnServerEvent:Connect(function(Player, Value)
PunchScript.Enabled = Value
end)
Not sure if I’ve missed anything here, hopefully not, but this should be the solution to your problem
No, you would only need a LocalScript and a ServerScript to interact with eachother with a RemoteEvent, with the ServerScript disabling the script you don’t want to be enabled. The actual script itself, in your case, the PunchScript, would stay exactly the way it is. If you look at where I put “Layout of the tool”
You can see the layout of the Tool itself. The spaces indicate it’s a child of the Tool, the dash indicates what that object actually is. Everything in my response is labelled and should be relatively easy to follow. You can literally just copy+paste the code I gave and organise your tool to look like that and it should (hopefully) work. Let me know if anything goes wrong.
Your script is a server script inside of the tool, no?
While the person above me solution while work, its way too complicated.
Just add a new server script in your code, delete the local script one, and paste this in:
-- local player cant be used in server scripts
local PunchScript = script.Parent.Parent.Parent.PlayerGui.Main.PunchScript
script.Parent.Equipped:Connect(function()
PunchScript.Enabled = false
end)
script.Parent.Unequipped:Connect(function()
PunchScript.Enabled = true
end)
Had to switch out the trye and false right here, it was making it so that the script work when the tool was held and didnt work when it wasnt being held
now the problem is that the tool doesnt work at all
First, we can simplify this slightly.
We don’t need two functions, we can use one and then find out which.
local PunchScript = game.Players.LocalPlayer.PlayerGui.Main.PunchScript
script.Parent:GetPropertyChangedSignal("Parent"):Connect(function()
if script.Parent.Parent:IsA("Model") then
PunchScript.Enabled = false
elseif script.Parent.Parent:IsA("BackPack") then
PunchScript.Enabled = true
end
end)
Also you can’t change the PunchScript’s Enabled property in a local script, this would have to be in a server script.
So let’s make it server-sided:
local PunchScript = game.Players[script.Parent.Parent.Parent.Name].PlayerGui.Main.PunchScript or game.Players:GetPlayerFromCharacter(script.Parent.Parent).PlayerGui.Main.PunchScript
script.Parent:GetPropertyChangedSignal("Parent"):Connect(function()
if script.Parent.Parent:IsA("Model") then
PunchScript.Enabled = false
elseif script.Parent.Parent:IsA("BackPack") then
PunchScript.Enabled = true
end
end)
To get PunchScript, it looks for the script by the player or the character, depending if it’s equipped or not, to prevent errors.
Another thing to mention, in this image you can see a CreateBullet remote event. This can be easily exploited, and the person can just spam bullets with this remote event. I would add a cooldown that if surpassed will kick the player, using player:Kick("Message").
I dont know if im doing something completely wrong (chance is I am) but this isnt working for me. Do I have to keep the PunchScript under the tool, or put it back where I had it before in starterGui
Out of curiosity, what is your reasoning behind using GetPropertyChangedSignal over Equipped/Unequipped? Doesn’t more logic make it more confusing and less explicit? Meriting the need for a heap of comments as opposed to just using a method/event pair that explicitly states what causes what in the code?