Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 7 years ago

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:

01local Gib = game.ReplicatedStorage:WaitForChild("Gib")
02Player = game.Players.LocalPlayer
03Mouse = Player:GetMouse()
04tool = script.Parent.ToolData
05k = script.Parent.HotkeyData
06buttonPressed = false
07 
08 
09 
10function Press(key)
11  if (key == k.Value) and game.ServerStorage:FindFirstChild(tool.Value) ~= nil then
12 
13    local Check = game.Players:FindFirstChild(Player)
14    if Check then
15        Gib:FireServer(Check, "Hyperlaser")
View all 36 lines...

And here is the Script:

01local ReplicatedStorage = game:GetService("ReplicatedStorage")
02local Players = game:GetService("Players")
03 
04local RemoteEvent = Instance.new("RemoteEvent",ReplicatedStorage)
05RemoteEvent.Name = "Gib"
06 
07local function ForThePlayers(Player, Item)
08    print ("Event recieved")
09    if Player.Backpack:FindFirstChild(Item.Value) == nil and Player.Character:FindFirstChild(Item.Value) == nil then
10    local weapon = game.ServerStorage:FindFirstChild(Item.Value):clone()
11    weapon.Parent = Player.Backpack
12    print ("Event executed")
13    end
14    end
15RemoteEvent.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.

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. kekistanguard 0 — 7y
0
@kek ;_; ik but im trying tho pls don't judge ;;;;_____;;;;; sahadeed 87 — 7y
0
What is "Player" defined as in the localscript? Cause if it's actually just the localplayer then try FindFirstChild(Player.Name) instead. Optimalpokemon123 37 — 7y
0
Oh lol I just realised that you have shown what you defined it as. I'm stupid. Optimalpokemon123 37 — 7y

1 answer

Log in to vote
0
Answered by
hellmatic 1523 Moderation Voter
7 years ago
Edited 7 years ago

Local Script works like this;

1local PrintEvent = game.ReplicatedStorage:WaitForChild('Print') -- Print is a RemoteFunction
2 
3local Text = "test" -- this is what will be sent to the server script by the local script
4 
5--Fire the PrintEvent to the server
6 
7PrintEvent:FireServer(Text) -- sends Text to the server script

Server Script

1local PrintEvent = game.ReplicatedStorage:WaitForChild('Print')
2 
3PrintEvent.OnServerEvent:connect(function(player, text) -- the first parameter is always the player who fired the PrintEvent from a localscript
4    print("recieved " .. text .. " from" .. player.Name .. "!")
5end)
0
Change your Player to Player = game.Players:FindFirstChild(game.Players.LocalPlayer.Name) hellmatic 1523 — 7y
0
add a elseif not Check then print('no player') hellmatic 1523 — 7y
0
instead of Mouse.Keydown it's Mouse.Button1Down hellmatic 1523 — 7y
0
THANK YOU SO MUCH!!! When I get home I will do what you said. sahadeed 87 — 7y
Ad

Answer this question