Why isnt this script working?

This is my script, and i cant get it to work at all. :frowning: Please help me find out whats wrong. (Idc about the skin part yet, just the killing)

inside the script
local message = game.StarterPack.Tool.ScreenGui.Texthere.Text

local player = game:GetService("Players").LocalPlayer.Character.Humanoid

game.ReplicatedStorage.RemoteEvent.OnServerEvent:connect(function(player)

message = ("You will die in five seconds.")

wait(5)

player.Health=0

end) 
inside the local script, which is in the tool
local killevent = game.ReplicatedStorage.killevent

local randomizer = math.random(1,2)

local tool = script.Parent

local debounce = false

tool.Activated:Connect(function()

if not debounce then

debounce = true

if randomizer == 1 then killevent:FireServer()

else

if randomizer == 2 then Changeskinevent:FireServer()

wait(1)

debounce = false

end

end

end)
Inside my explorer

Mind explaining what it does? It’s a little hard to fix it if I don’t know what it’s trying to achieve or what is going wrong exactly.

if randomizer == 2 then Changeskinevent:FireServer()

This line is your problem Changeskinevent is not defined anywhere.

In the first script this is your problem.

game.ReplicatedStorage.RemoteEvent.OnServerEvent:connect(function(player)

Your remote event that you are calling is non existent.

1 Like

You cannot use LocalPlayer in a regular script on the server.

1 Like

A few interesting things to point out here:

local player = game:GetService("Players").LocalPlayer.Character.Humanoid

game.ReplicatedStorage.RemoteEvent.OnServerEvent:connect(function(player)

.LocalPlayer indicates that this is a local script, but then .OnServerEvent indicates it’s a server script. You’ll want that to be a server script, then obviously you cannot get local player from the players service. Inside the remote event function, you can see that the player is already passed as the argument. Get the humanoid from that player, somewhat like you did above, then set its health to 0.

Another thing with this bit:
game.ReplicatedStorage.RemoteEvent.OnServerEvent:connect(function(player)

I don’t see an event in your replicated storage with the name of “RemoteEvent”. You’ll want to correct that to killevent, as is indicated in your local script.

Edit: Whoops replied to @Vmena , meant to reply to OP.

2 Likes

Before I added the changeskinevent, it wasnt workking.thanks though :slight_smile:

So, should I remove local from player = game…?

What should i change RemoteEvent to then? killevent?

Your first problem is if you are using a server script you can not use "LocalPlayer" to define the player. LocalPlayer is used for defining on the client, so can mostly be towards GUI’s. 2nd you must define your remote events, so the script knows what they are and where they are located. One way of defining the player on the server is by creating a function and using the "PlayerAdded" event, here is an example:

game.Players.PlayerAdded:Connect(function(player)
-- script here
end)

Here is a Remote Event Article: RemoteEvent | Documentation - Roblox Creator Hub

1 Like
player = game:GetService("Players").LocalPlayer.Character.Humanoid

thats not fine?

how do I do that???

1 make sure to read the article I provided you to answer any remote event questions. 2 Yes in your script you see where you say “LocalPlayer” that can only be used for defining the player on the client, but this is server sided, so you need to define it in a way the server can understand like the example I provided you with.

local player = game.Players.PlayerAdded:Connect(function(player) 
player = game.Players.PlayerAdded:Connect(function(player)

which one?

I do not think you quite understand, I have created a function for you that already defines the player, “player =” is not necessary for this. Make sure you understand functions and the difference between the client and server before you ask this question. And try not to ask questions that will lead you to more questions.

Here is an article on functions: Functions | Documentation - Roblox Creator Hub

like this? Sorry i’m pretty new to programming…


game.Players.PlayerAdded:Connect(function(player)

game.ReplicatedStorage.RemoteEvent.OnServerEvent:connect(function(player)

message = ("You will die in five seconds.")

wait(5)

player.Health=0

end)

yes now you are getting the hang of it, btw the “player” in the parenthesis of the 2nd line is not necessary. that should fix your server’s problem, now in the local script make sure you define your events and fire them correctly. Also what is “message” in the server script?

1 Like