Hello !
(sorry for my bad english)
I’m actually doing a specific DeathScreen for specific situation:
For example, if someone die in a supermarket (for example), his death screen will be different if he die in a forest (for example).
When a player is added, a value called DeathMessage is created (it work)
When the player touch a part, his DeathMessage changed (and this doesn’t work)
Here is the script I’ve tried:
script.Parent.Touched:Connect(function(hit)
if hit.Parent ~= nil then
if hit.Parent:findFirstChild("Humanoid") ~= nil then
hit.Parent:findFirstChild("Humanoid").Health = hit.Parent:FindFirstChild("Humanoid").Health - 100
hit.Parent:WaitForChild("Settings"):WaitForChild("DeathMessage").Value = "You are jailed in the Supermarket."
wait(3)
hit.Parent.Settings:WaitForChild("DeathMessage").Value = "You fail the experience."
end
end
end)
I also tried with LocalScript but when I just put a “print()” it didn’t work.
The DeathMessage does not change because you are trying to do it from a LocalScript, in order to do this you will need to have a RemoteEvent in ReplicatedStorage and you will need to fire a ServerScript in order to change the value.
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
hit.Parent.Humanoid.Health = 0 --No need to check for the child, you already are doing an if statement to see if it is there
local s = hit.Parent:WaitForChild("Settings") --Much more efficent
local d = s:WaitForChild("DeathMessage") --Again, more efficient
d.Value = "You are jailed in the Supermarket." --Don't find first child for each part, just make a variable
wait(3)
d.Value = "You fail the experience." --again, a variable
end
end)
That code is very messy, I cleaned it and changed it for you. What I did should work.
I do suggest doing what @ThousandDegreeKnife mentioned, but if you cannot do it let me know, I can program you a quick script to do what TDK has mentioned.
Edited once more, to make it a bit more efficent and working, if it isn’t working let me know, this should work, keep in mind this is a very basic script and way to do it, and I do not recommend doing it. If you need help, here are some sources;
I tried the script that you gives me and it print : “Infinite yield possible on ‘Workspace.mist0s:WaitForChild(“Settings”)’” but the Settings is in the Players.(local player)
And thanks for the answer !!!
Here’s a super simple way of scripting a Death Screen.
Server Script inside the Kill Part
local replicatedStorage = game:GetService("ReplicatedStorage")
script.Parent.Touched:Connect(function(hit)
local hum
if hit.Parent:FindFirstChild("Humanoid") and game.Players:FindFirstChild(hit.Parent.Name) then -- Ensure the player is an actual player
hum = hit.Parent.Humanoid
if hum.Health > 0 then -- If the player is not dead
hum.Health = 0
replicatedStorage.RemoteEvent:FireClient(game.Players:GetPlayerFromCharacter(hit.Parent), "You have died in the Supermarket!")
end
end
end)
Local Script inside a GUI
local replicatedStorage = game:GetService("ReplicatedStorage")
local player = game.Players.LocalPlayer
replicatedStorage.RemoteEvent.OnClientEvent:Connect(function(deathMessage)
local textLabel = script.Parent.TextLabel
textLabel.Text = deathMessage
end)
(Make sure to place a RemoteEvent in ReplicatedStorage)
OMG, it work, really thanks.
But I don’t understand how the string “You have died…” can change with the same remote event. If you can, can you explain me ?
Really thanks for answer !