I’m so confused… I was trying to make a remote event that fires and then gives the said player a tool but now it’s decided it doesn’t wanna work. it was working fine earlier but now its broken.
Ok soo, to help you further, can you send your full script? Also, it would help if you could tell me what specifically isn’t working, for example, any error messages you get or whether the “Received” is printed in the output when you push the button.
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local hrp = char:WaitForChild("HumanoidRootPart")
local cam = workspace.CurrentCamera
local CamPart = game.Workspace:WaitForChild("CamPart")
cam.CameraType = Enum.CameraType.Scriptable
game.Lighting.StartingBlur.Enabled = true
local teamEvent = game.ReplicatedStorage.TeamChange
local FightingToolsFolder = game.ReplicatedStorage:FindFirstChild("FightingTools")
local WerewolfPunch = FightingToolsFolder:WaitForChild("WerewolfPunch")
local camOn = true
local Gui = script.Parent
local playButton = script.Parent.Play
local werewolfButton = script.Parent.Wolf
local SharkButton = script.Parent.Shark
werewolfButton.Transparency = 1
werewolfButton.UIStroke.Transparency = 1
SharkButton.Transparency = 1
SharkButton.UIStroke.Transparency = 1
hum.WalkSpeed = 0
hum.JumpHeight = 0
Gui.Enabled = true
playButton.Transparency = 0
playButton.UIStroke.Transparency = 0
SharkButton.Interactable = false
werewolfButton.Interactable = false
playButton.Interactable = true
function ClearTrans()
game.Lighting.StartingBlur.Enabled = false
Gui.Enabled = false
werewolfButton.Transparency = 1
werewolfButton.UIStroke.Transparency = 1
SharkButton.Transparency = 1
SharkButton.UIStroke.Transparency = 1
SharkButton.Interactable = false
werewolfButton.Interactable = false
playButton.Interactable = false
hum.WalkSpeed = 16
hum.JumpHeight = 7.2
cam.CameraType = Enum.CameraType.Custom
camOn = false
end
playButton.MouseButton1Click:Connect(function()
playButton.Transparency = 1
playButton.UIStroke.Transparency = 1
werewolfButton.Transparency = 0
werewolfButton.UIStroke.Transparency = 0
SharkButton.Transparency = 0
SharkButton.UIStroke.Transparency = 0
SharkButton.Interactable = true
werewolfButton.Interactable = true
playButton.Interactable = false
end)
werewolfButton.MouseButton1Click:Connect(function()
ClearTrans()
hrp.CFrame = game.Workspace:WaitForChild("WerewolfSpawn").CFrame + Vector3.new(0,3,0)
teamEvent:FireServer("Wolves")
game.ReplicatedStorage.ClassTool:FireServer()
end)
SharkButton.MouseButton1Click:Connect(function()
ClearTrans()
hrp.CFrame = game.Workspace:WaitForChild("SharkSpawn").CFrame + Vector3.new(0,3,0)
teamEvent:FireServer("Sharks")
end)
while camOn do
cam.CFrame = game.Workspace.CamPart.CFrame
task.wait(.1)
end
Server:
local Player = script.Parent.Parent.Parent
local character = Player.Character or Player.CharacterAdded:Wait()
local tool = script.Parent
local hitbox = tool.Hitbox
local animation = tool.Animation
local attacking = false
local animdb = false
local debounce = false
local cooldown = 1
local force = 25
game.ReplicatedStorage:WaitForChild("ClassTool").OnServerEvent:Connect(function(player)
print("Received")
local WerepunchClone = game.ReplicatedStorage.FightingTools.WerewolfPunch:Clone()
WerepunchClone.Parent = player.Backpack
end)
local function knockback(hum)
local rootPart = hum.Parent:FindFirstChild("HumanoidRootPart")
if rootPart then
local bodyVelocity = Instance.new("BodyVelocity")
bodyVelocity.Velocity = character.HumanoidRootPart.CFrame.LookVector * force -- Adjust the multiplier for desired knockback force
bodyVelocity.P = 1250
bodyVelocity.MaxForce = Vector3.new(100000, 100000, 100000)
bodyVelocity.Parent = rootPart
game:GetService("Debris"):AddItem(bodyVelocity, 0.25) -- Remove the force after 0.5 seconds
end
end
tool.Activated:Connect(function()
if animdb == false then
animdb = true
character:WaitForChild("Humanoid").WalkSpeed = 5
attacking = true
tool.Parent:FindFirstChild("Humanoid").Animator:LoadAnimation(animation):Play()
wait(2)
character:WaitForChild("Humanoid").WalkSpeed = 16
wait(cooldown)
attacking = false
debounce = false
animdb = false
end
end)
tool.Hitbox.Touched:Connect(function(hit)
if attacking and hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name ~= tool.Parent.Name then
if not debounce then
debounce = true
knockback(hit.Parent:FindFirstChild("Humanoid"))
hit.Parent:FindFirstChild("Humanoid"):TakeDamage(10)
--Hitsound:Play()
--Hitsound.RollOffMaxDistance = 50
--Hitsound.RollOffMinDistance = 1
end
end
end)
its late for me so i’ll be getting off but if you can help that would be appreciated .
Have you tried printing in the MouseButton1Click event? Maybe the local script is in an infinite yield with the WaitForChild()s thus the event wasn’t connected.
Oh wait. Does this happen after the player respawns? If so (which I assume to be the case), you must put the player variables at the top inside each connections. The player variables at the top will only work during the first life of the player. If the player dies, the player’s old character will be automatically destroyed and replaced with a new one. The char variable will only refer to the first character of the player. It won’t change whenever the player respawns. The same thing applies to the Humanoid and HumanoidRootPart.
If this is actually the case, the reason why it won’t work is due to the hrp being inaccessible because it got destroyed. To fix this, you just get the player’s character again using the plr variable instead of setting a char variable at the top.
werewolfButton.MouseButton1Click:Connect(function()
ClearTrans()
local char = plr.Character
if char == nil or char.Parent == nil then return end
local hrp = char:FindFirstChild("HumanoidRootPart")
if hrp == nil then return end
hrp.CFrame = workspace:WaitForChild("WerewolfSpawn").CFrame + Vector3.new(0,3,0)
teamEvent:FireServer("Wolves")
game.ReplicatedStorage.ClassTool:FireServer()
end)
You can also do the same with every block of code that uses the char, hum, and hrp variables.
P.S. You don’t need to pass the plr variable in FireServer() since OnServerEvent already has the player variable.
Check if you have multiple ClassTool / teamEvent remoteEvents in the same location. If there are multiple in the same location with the same name, you could be firing one and listeneing to another.
You should also check on the server (Where you call .OnServerEvent) if that code is running. Insert a print above the .OnServerEvent to check whether or not the server is actually registering the event.
I think i found the problem. Yesterday I was thinking that the problem was because the attack script (receiving script) was in the tool. I’m pretty sure that’s the case because the tool is located in replicated storage. How would I fix this though because I don’t want to make an individual script for each tool located in serverscriptservice