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

My script does not fire an event to the server when it is supposed to. How do you fix this issue?

So I just started learning FilteringEnabled, and I wanted to learn it while I am making a battle royale game. I wanted a local script to fire an event to the server so that a script picks it up, but the local script does not even fire at all! So, here is the local:



local Gib = game.ReplicatedStorage:WaitForChild("Gib")
Player = game.Players.LocalPlayer
Mouse = Player:GetMouse()
tool = script.Parent.ToolData
k = script.Parent.HotkeyData
buttonPressed = false



function Press(key)
  if (key == k.Value) and game.ServerStorage:FindFirstChild(tool.Value) ~= nil then
	
	local Check = game.Players:FindFirstChild(Player)
	if Check then
		Gib:FireServer(Check, "Hyperlaser")
		print ("Event fired")
	end
	
	if Player.Backpack:FindFirstChild(tool.Value) == nil and Player.Character:FindFirstChild(tool.Value) == nil then
	local weapon = game.ServerStorage:FindFirstChild(tool.Value):clone()
	weapon.Parent = Player.Backpack	
	repeat
   		Player.PlayerGui:FindFirstChild("HotKeyGuiThing"):remove()	
	until Player.PlayerGui:FindFirstChild("HotKeyGuiThing") == nil
	if workspace:FindFirstChild("Weapon Crate") then workspace["Weapon Crate"]:Destroy()
	end
	end
	
 end
end

Mouse.KeyDown:connect(Press)
wait (2)
repeat
   	Player.PlayerGui:FindFirstChild("HotKeyGuiThing"):remove()	
until Player.PlayerGui:FindFirstChild("HotKeyGuiThing") == nil

And here is the Script:


local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

local RemoteEvent = Instance.new("RemoteEvent",ReplicatedStorage)
RemoteEvent.Name = "Gib"

local function ForThePlayers(Player, Item)
	print ("Event recieved")
	if Player.Backpack:FindFirstChild(Item.Value) == nil and Player.Character:FindFirstChild(Item.Value) == nil then
	local weapon = game.ServerStorage:FindFirstChild(Item.Value):clone()
	weapon.Parent = Player.Backpack	
	print ("Event executed")
	end
	end
RemoteEvent.OnServerEvent:Connect(ForThePlayers)

My script might have some other issues, because what I like to do is to take some scripts from the RWiki and change them to my command, because I am still a beginner scripter, so please don't judge my skill. And if you do find those issues, give feedback please.

4 comments

0

God, I hate FilteringEnabled. Because you are a noob, just avoid it. I like the functionality of not having people under 13 visiting my game.

0

@kek ;_; ik but im trying tho pls don't judge ;;;;_____;;;;;

0

What is "Player" defined as in the localscript? Cause if it's actually just the localplayer then try FindFirstChild(Player.Name) instead.

0

Oh lol I just realised that you have shown what you defined it as. I'm stupid.

1 answer

✓ Accepted answer

Local Script works like this;

local PrintEvent = game.ReplicatedStorage:WaitForChild('Print') -- Print is a RemoteFunction

local Text = "test" -- this is what will be sent to the server script by the local script

--Fire the PrintEvent to the server

PrintEvent:FireServer(Text) -- sends Text to the server script

Server Script

local PrintEvent = game.ReplicatedStorage:WaitForChild('Print')

PrintEvent.OnServerEvent:connect(function(player, text) -- the first parameter is always the player who fired the PrintEvent from a localscript
	print("recieved " .. text .. " from" .. player.Name .. "!")
end)

4 comments

0

Change your Player to Player = game.Players:FindFirstChild(game.Players.LocalPlayer.Name)

0

add a elseif not Check then print('no player')

0

instead of Mouse.Keydown it's Mouse.Button1Down

0

THANK YOU SO MUCH!!! When I get home I will do what you said.

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