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

Script work in test mode but in normal servers not, why?

Asked by 6 years ago
Edited 6 years ago

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()
0
Please don't waste ram on a variable you never use. You made a variable in the script on line 2, so use it! hiimgoodpack 2009 — 6y
0
In normal testing mode it always has FE off. If your game has FE on you need to press the start button near the test button to see if it works with FE on. Viking359 161 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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 playerinstead 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!

Ad

Answer this question