Dear reader, I'm currently having trouble with a script i'm making, i'm kinda new to scripting so I don't know much but I don't know whats wrong here, though I thought I did everything right, I have 2 scripts, one a local script, What it does is gets information from the local script and sends it to the Serverscript and kills a player (I'm doing this so i can learn, not just making a kill GUI)
Here's The Serverscript:
game.ReplicatedStorage.KillEvent.OnServerEvent:Connect(function() x = workspace:FindFirstChild(target) x.Humanoid.Health = 0 end)
And Here's The LocalScript
rs = game:GetService("ReplicatedStorage") x = rs.KillEvent target = script.Parent.Parent.CurrentTarget script.Parent.MouseButton1Click:Connect(function() x:FireServer(target) end)
Thanks for reading this, Help is appreciated.
Howdy!
This is a security feature implemented within the last year where scripts need to abide by FilteringEnabled
rules. This means that the client is cut off entirely from the server, which means that if your client says "this player has a gun", the server won't listen and other players can't see it. In order to go around this, we have to use RemoteEvents
. You can learn more about those here and here.
This is the example that Roblox uses to show how using a RemoteEvent
works (when in terms of client-server communication). Your local script would look like what we have below.
local ReplicatedStorage = game:GetService("ReplicatedStorage") local createPartEvent = ReplicatedStorage:WaitForChild("CreatePartEvent") createPartEvent:FireServer(BrickColor.Green(), Vector3.new(10, 20, 0))
And your server script would look like what is below.
local ReplicatedStorage = game:GetService("ReplicatedStorage") local createPartEvent = Instance.new("RemoteEvent", ReplicatedStorage) createPartEvent.Name = "CreatePartEvent" local function onCreatePartFired(player, color, position) print(player.Name, "wants to create a part") local newPart = Instance.new("Part") newPart.BrickColor = color newPart.Position = position newPart.Parent = game.Workspace end createPartEvent.OnServerEvent:Connect(onCreatePartFired)
Essentially, you need to use :FireServer()
from the client to tell the server to run the code you want so that EVERYONE can see it.
If this helped you out, consider accepting this answer for those sweet, sweet reputation points. If not, comment below and I (or someone else) will help you out.