I’ve been trying to make a weapon from scratch, but I’m not the best scripter, just a beginner. I tried to script up a weapon, but the damage only works in single-player studio runs (testing on NPC dummies), not in-game or if I try to run local server test in studio.
Here is the full script:
(Script>Tool>Handle)
local debounce = false
local function onTouched(hit)
if debounce == false then
debounce = true
hit.Parent.Humanoid:TakeDamage(24)
wait(3)
debounce = false
end
end
script.Parent.Touched:Connect(onTouched)
EDIT:
Alright, I tried using RemoteEvent but I’m not sure how to do this. What I have so far is a fire script for a remote event.
game.ReplicatedStorage.Damage:FireServer(Someone)
-- "Someone" is script.Parent.Touched
How do I make a Remote Event that does damage to “Someone”?
Is this in a local script? If any part of this system is in a local script, it won’t get replicated to the server (except in special circumstances). If it doesn’t get replicated to the server, other players won’t see it. The reason it may appear to work in studio is because the information your seeing in the explorer and properties windows are representative of what your client sees. The server may not necessarily be the same.
You should instead use a remoteEvent (i think it was that one) to send information to the server, then have a server script deal the damage instead (send the amount of dmg, and who got hit)
add a second dmg value, then, in a server script, receive the FireServer (I forgot what exactly your supposed to use), and put the damaging thing there (the humanoid:TakeDamage part)
and remember the first value is the sender, so it should be like (plr, someone, dmg)
You shouldnt need a remote event to do all this stuff… ill give you some code, and tell me if it works…
local debounce = false
local function onTouched(hit)
if hit.Parent ~= nil then
local human = hit.Parent:FindFirstChildOfClass("Humanoid")
if human then
if debounce == false then
debounce = true
human.Health -= 24
wait(3)
debounce = false
end
end
end
end
script.Parent.Touched:Connect(onTouched)
remoteEvent.OnServerEvent:Connect(function(player) --player is character thats receiving the remote event
local character = player.Character
local human = character:FindFirstChildOfClass("Humanoid")
human.Health -= 24
end)
If it works, you should select my reply as solution, or add “[SOLVED]” in the title. This is to prevent players from clicking on a topic that is solved.