I have 2 scripts (1 local script and 1 script ) comunicating with a remote event from the server to the client for killing once every player that enters the game. The problem i have is, in the test mode inside roblox studio it Works and kill me, but when i go to the normal servers it don't kill me. The script is inside the server script service and the local script is inside the starter pack. Someone knows why?
Script
local Players = game:GetService("Players") local ReplicatedStorage = game:GetService("ReplicatedStorage") local KillNewPlayers = Instance.new("RemoteEvent") KillNewPlayers.Parent = game.ReplicatedStorage KillNewPlayers.Name = "KillNewPlayers" local function onPlayerAdded(player) KillNewPlayers:FireClient(player) end Players.PlayerAdded:Connect(onPlayerAdded)
Local script
local Players = game:GetService("Players") local ReplicatedStorage = game:GetService("ReplicatedStorage") local char = game.Players.LocalPlayer.Character local KillNewPlayers = ReplicatedStorage:WaitForChild("KillNewPlayers") KillNewPlayers.OnClientEvent:Connect() wait(1) char.Humanoid.Health = 0 wait(1) game.Players.LocalPlayer.Backpack.KillNewPlayers:Destroy() game.StarterPack.KillNewPlayers:Destroy()
This won't work because 1, you never connected a function to line 7 on the LocalScript
, and 2, you need to use the variable player
instead of LocalPlayer
, as so:
Server Script (Server):
local ReplicatedStorage = game:GetService("ReplicatedStorage") local KillNewPlayers = Instance.new("RemoteEvent") KillNewPlayers.Parent = game.ReplicatedStorage KillNewPlayers.Name = "KillNewPlayers" game.Players.PlayerAdded:Connect(function(plyr) --When the player joins, we call it "plyr" local playerToKill = plyr --We need to specify what player we want to kill, which is the player who joined. KillNewPlayers:FireClient(plyr,playerToKill) --Fire the remote event to the player, then fire who we want to kill. end)
Local Script (Client):
local ReplicatedStorage = game:GetService("ReplicatedStorage") local KillNewPlayers = ReplicatedStorage:WaitForChild("KillNewPlayers") KillNewPlayers.OnClientEvent:Connect(function(p) --When the event is fired, we get the player who we want to kill. wait(1) p.Character.Humanoid.Health = 0 --Set it's health to 0 p.Backpack.KillNewPlayers:Destroy() --Destroy whatever was in it's backpack --Removing it from the StarterPack is not needed. end)
A good example can be found here. I have tested this, and it works 100%. Please accept my answer if this helped!