Currently, I need to make a demo ending for my game.
This ending will eventually become the ‘Sad’ ending, and I want to trigger it upon touch on a specific part.
I have already made some code for it, but not that much.
local ending
local humanoid = ???
-- Ending
ending = humanoid.Died:Connect(function()
[ENDING GOES HERE]
end)
Only problem is, I don’t know how to get the humanoid, I don’t know how make the ending only happen to the player that touched the lava, not everyone else, and then do my teleporting process [Like post-credits, credits, etc.]
[AGAIN: Only for the one player that touched it. If multiple people touch it it’ll happen to them too.]
Any people that can help with code or good tips, will be greatly appreciated and will be listed in the games movie style credits and the end of the game for all to see.
You could run the ending in a local script so it only happens locally. And to get the humanoid just either get the plr and then get the character from the plr and get the humanoid that way or in a server script detects when a player joins, get the chracter from the plr that joins and then get the humanoid from there. You would just then need to fire to the client to run the ending.
If you want to make the ending happen in a different place like what some games do then you can just do everything inside of the server script and then use the teleportation service to teleport the plr to a different place. You could also use a touch detector to see if someone touches the lava and if they die from touching the lava then run the code.
I am not 100% what you mean by “Only for one player that touched it. If multiple people touch it it’ll happen to them too.” but if you mean you want only one person in the server to be able to get the ending you can just have a variable which is set to false at the start but then when a plr touches the lava and dies then you change the variable to true and use an if statement to see if it is false or true to know if the ending should run or not (would only work in a server script cuz of local scripts running locally)
2 Likes
This wasn’t really helpful. I do all Story stuff in a Server Script unless if it’s a remote event. Thank you for trying though.
1 Like
Well there is really no way to make something to happen to only one person server side. The only way like I said would be via a local script. (just use a remote event if u need the script to be server script)
3 Likes
Like LifeDigger said, there isn’t any way to make something happen to only one person on a server script, you can use remote events for the server to communicate with the client, or vice versa.
The easiest way to go about this would be to use a “Server to Client” remote event.
Server Script:
local Lava = game.Workspace.lava --the lava part that you want to trigger the ending
local ReplicatedStorage = game:GetService("ReplicatedStorage") --replicated storage
local Event = ReplicatedStorage.RemoteEvent --the remote event
Lava.Touched:Connect(function(hit) --fires when someone touches the part
local plr = game.Players:FindFirstChild(hit.Parent.Name) --finds the player
Event:FireClient(plr) --fires the remote event
end)
Local Script:
local ReplicatedStorage = game:GetService("ReplicatedStorage") --replicated storage
local Event = ReplicatedStorage.RemoteEvent --remote event
local function End() --function
print("ended") --put what you want to happen when they touch the part here
end
Event.OnClientEvent:Connect(End) --fires the function once the remote event is fired
If you decide to use the examples above, place the local script in StarterPlayerScripts and place the server script in the part.
You can learn more about Remote Events using the link below.
1 Like