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 6 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:



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.

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 — 6y
0
@kek ;_; ik but im trying tho pls don't judge ;;;;_____;;;;; sahadeed 87 — 6y
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 — 6y
0
Oh lol I just realised that you have shown what you defined it as. I'm stupid. Optimalpokemon123 37 — 6y

1 answer

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

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)
0
Change your Player to Player = game.Players:FindFirstChild(game.Players.LocalPlayer.Name) hellmatic 1523 — 6y
0
add a elseif not Check then print('no player') hellmatic 1523 — 6y
0
instead of Mouse.Keydown it's Mouse.Button1Down hellmatic 1523 — 6y
0
THANK YOU SO MUCH!!! When I get home I will do what you said. sahadeed 87 — 6y
Ad

Answer this question