How to make script FE compatible?

hi, it’s me again the last script from the last post didn’t work so I found this script and modified. But the problem is that its not FE compatible. my sword script (the one below) is supposed to damage the player but doesn’t. Any help

local debounce = false

local function onTouched(hit)
    if (hit.Parent:findFirstChild("Humanoid")~= nil) and script.Parent.Swinging.Value == true then 
        if not debounce then
        debounce = true
        hit.Parent.Humanoid:TakeDamage(40) 
        wait(10)
        debounce = false    
        end
    end
end

script.Parent.Union.Touched:Connect(onTouched)

and again, I am sorry if a being too needy but I am a HUGE noob at scripting and any help with my taken thanks.

Is it in a local script or in a serverside script?

its a local script. i tried it as a server script and its doesnt work.

Could you tell me what didn’t work when you put it in a server script?

i mean nothing. whenever i try to attack someone, no damage is being done.

Clients cannot damage other humanoids, so the server needs to take care of that.
This may not be working in a server script because of your swinging value (which I don’t know anything about). Your code worked for me otherwise.

here are some good reads

Usually when a classic sword relies on the Touched event it would use a server script in the blade/handle for detecting touch events and dealing damage, while a local script in the tool would handle user input like clicking their mouse to swing or lunge.

The script you posted should definitely be a server script, but like @imalex4 said if that script.Parent.Swinging.Value is being changed by the local script, the server script won’t detect the change. Removing that check might make the sword work.

the swinging value is not for damaging, its for an animation that i have

But what we mean is that if a local script is changing that value, then the server script with the Touched event won’t recognize the change since from the server’s perspective that value will always be ‘false’

Well, I will show you a basic script which works for hit and damage on the server, and try to make something from it.

local Debounce = false
workspace.Baseplate.Touched:Connect(function(hit)
	if Debounce == false and hit.Parent:FindFirstChild("Humanoid") then
		Debounce = true
		hit.Parent.Humanoid:TakeDamage(50)
		wait(3)
		Debounce = false
	end
end)

Also remember this anything done on the client will only show for the client, for example if I delete a baseplate, it will only delete for me. Only things on the server replicate for everyone

1 Like

Try changing your script to this and let us know if it works:

local debounce = false

local function onTouched(hit)
    --if (hit.Parent:findFirstChild("Humanoid")~= nil) and script.Parent.Swinging.Value == true then 
    if (hit.Parent:FindFirstChild("Humanoid") ~= nil) then
        if not debounce then
        debounce = true
        hit.Parent.Humanoid:TakeDamage(40) 
        wait(10)
        debounce = false    
        end
    end
end

script.Parent.Union.Touched:Connect(onTouched)

the script is still not FE compatible, when ever i kill someone, on my screen they die, but on theirs they didnt.

That’s what we been saying. The reason is your executing it from a local script anything run on a local script will ONLY show for the player/Client. That;s why you have to do it from the server, so it replicates to everyone

Run it from a serverscript.

1 Like

thanks for the help, i am a huge idiot.

but i still have a quick question, how will i incorporate the swinging value in the script.

Why don’t you give it a try first and if you need help ask me in DMS.