This is my script, and i cant get it to work at all. 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)
.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.
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)
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.
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.
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?