Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Remote Events not firing from LocalScript?

So I made a Handcuffs tool that is supposed to fire a RemoteEvent that changes the BoolValue in a character's Humanoid to true which will trigger the criminal to be arrested and it is also supposed to fire a RemoteEvent that gives the player who arrested him the bounty of the criminal.

The problem is that both Remote Events are not firing. The BoolValue is not changing and the bounty is not being claimed since nothing is printing in the output.

I made a PlayerAdded event that creates IntValues named "Bounty" and "CurrentExp" which are parented to the player.

I also made 2 Remote Events named "ArrestPlayer" and "ClaimBounty" which are in ReplicatedStorage.

This is the LocalScript in the Handcuffs tool that fires the Remote Events:

local camera = workspace.CurrentCamera
local length = 20
local localPlayer = game.Players.LocalPlayer
local mouse = nil

script.Parent.Equipped:Connect(function(m)
	mouse = m
	m.Icon = "rbxassetid://4952930813"
end)

script.Parent.Activated:Connect(function()
	if mouse then
		local unitRay = camera:ScreenPointToRay(mouse.X, mouse.Y)
		local ray = Ray.new(unitRay.Origin, unitRay.Direction * length)

		local target = workspace:FindPartOnRay(ray, localPlayer.Character)

		if target and target.Parent and target.Parent:FindFirstChild("Humanoid") then
			local playerTarget = game.Players:GetPlayerFromCharacter(target.Parent)
			if playerTarget then
				if playerTarget.Team == "Criminals" and target.Parent:WaitForChild("Humanoid").Health > 0 then
					print(target.Name)
					local RS = game:GetService("ReplicatedStorage")
					local arrest = RS:WaitForChild("ArrestPlayer")
					arrest:FireServer(playerTarget)
					local bountyremote = RS:WaitForChild("ClaimBounty")
					bountyremote:FireServer(playerTarget)
				end
			end
		end
	end
end)

These are the Scripts in ServerScriptService for those Remote Events:

Script 1:

local RS = game:GetService("ReplicatedStorage")
local arrest = RS:WaitForChild("ArrestPlayer")

local function arrested(player, playerTarget)
	local hum = playerTarget.Character:WaitForChild("Humanoid")
	hum.Arrested.Value = true
end

arrest.OnServerEvent:Connect(function(arrested)
	print("Arrested player")
end)

Script 2:

local RS = game:GetService("ReplicatedStorage")
local btyremote = RS:WaitForChild("ClaimBounty")

local function giveBounty(player, playerTarget)
	local exp = player.CurrentExp
	local bounty = playerTarget.Bounty
	exp.Value = exp.Value + bounty.Value
	print("Converted bounty into EXP")
	local plrStatus = player.PlayerGui.LevelGui.Status
	plrStatus.TextColor3 = Color3.fromRGB(0, 85, 255)
	plrStatus.Text = "You claimed a bounty of " ..bounty.Value.. "!"
	wait(3)
	plrStatus.Text = ""
end

btyremote.OnServerEvent:Connect(function(giveBounty)
	print("Claimed bounty for arrest")
end)

No errors are shown in the Output so I am pretty stumped on how to fix this.

2 answers

On local scripts you can only use FireClient because its only local if you wanted to do for the server use FireAllClients

2 comments

0

I'm trying to fire the OnServerEvent from the Local Script by clicking the tool so shouldn't I use FireServer?

0

A local script is not a server script so you can't use fire server if you try and use onserver event then use onclientevent!

Just fixed the problem. Turns out that it was because I said "Criminals" on Line 21 of the Local Script instead of game.Team.Criminals.

This discussion is preserved as it was. New answers, comments, and votes are closed.