Need scripting support! on remote events

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.

Client side (button press)

werewolfButton.MouseButton1Click:Connect(function()
	ClearTrans()
	hrp.CFrame = game.Workspace:WaitForChild("WerewolfSpawn").CFrame + Vector3.new(0,3,0)
	teamEvent:FireServer("Wolves")
	game.ReplicatedStorage.ClassTool:FireServer(plr)
end)

Server side (script in the punch tool)

game.ReplicatedStorage:WaitForChild("ClassTool").OnServerEvent:Connect(function(player)
	print("Received")
	local WerepunchClone = game.ReplicatedStorage.FightingTools.WerewolfPunch:Clone()
	WerepunchClone.Parent = player.Backpack
end)

Also the local script is in a gui

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.

I can tomorrow I’m not at my pc currently but basically the “received” print statement isn’t printing so I’m assuming the event isn’t running

Ok. Then, add a print statement in the client function and see if that prints.

you are sending in plr (localplayer i assume) in the local script fire server method

no need to do this, the player is automatically sent as an argument.

this might be what is messing it up.

I’m at my pc rn so ill send them.

Client:

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 :smiley: .

Alright. I gtg too but I’ll look at them tomorrow!

I have tried to remove the “plr” from the client but I’ll try again

Alright thank you for doing that!

I don’t think you should be attaching the server to listen to something in replicated storage. That would be my guess as to what is causing the issue.

You don’t need to put the player in the remote event as the server automatically gets the player with the remote event.

Reference to documentation:

Looking at the code if I am understanding this part right:

This gives you the specific classes weapon, so why don’t you give it to the player when they send the event to pick the class.

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.

1 Like

I have not reset and it still doesn’t give the tool.
I’ve added some print statements and the “clicked” statement is fired but the received is not?

werewolfButton.MouseButton1Click:Connect(function()
	ClearTrans()
	hrp.CFrame = game.Workspace:WaitForChild("WerewolfSpawn").CFrame + Vector3.new(0,3,0)
	teamEvent:FireServer("Wolves")
	print("Clicked")
	game.ReplicatedStorage.ClassTool:FireServer()
end)

it does print and all of the code before the remote event firing works perfectly fine (it teleports the player and assigns the team)

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.

Edit: Where is the serverscript located?

--Client
local werewolfButton = ????
local rs = game:GetService("ReplicatedStorage")
local classToolEvent = rs:WaitForChild("ClassTool")

werewolfButton.MouseButton1Click:Connect(function() ClearTrans()
	hrp.CFrame = workspace.WerewolfSpawn.CFrame + Vector3.yAxis * 3
	teamEvent:FireServer("Wolves")
	classToolEvent:FireServer()
end)

--Server
local rs = game:GetService("ReplicatedStorage")
local classToolEvent = rs:WaitForChild("ClassTool")

classToolEvent.OnServerEvent:Connect(function(player)
	local tool = rs.FightingTools.WerewolfPunch:Clone()
	tool.Parent = player.Backpack
end)

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