My current Obby, with help, We created an “OnServerInvoke” GUI button which is triggered by a player standing on the last checkpoint. You then press the button and it transports you back to the beginning.
However, I no longer want it to activated by a button. I want it just happen when they stand on the last checkpoint. I tried to link it to an ontouch event but it failed. Any help understanding how to do it is appreciated.
This is the script on the Leaderstats page
game.ReplicatedStorage.Prestige.OnServerInvoke = function (player)
if player.leaderstats.Node.Value == 42 then
player.leaderstats.Prestige.Value += 1
player.leaderstats.Node.Value = 0
player:LoadCharacter()
end
end
This code I have on touch, when I touch the last checkpoint
local part = script.Parent
part.Touched:Connect(function(hit) -- this event fires whenever something touches the part
if hit.Parent:FindFirstChild("Humanoid") then -- if humanoid exists
local player = game.Players:GetPlayerFromCharacter(hit.Parent) -- gets the player from the character
if player then -- if player exists
if not player.PlayerGui.ScreenGuiRB.PrestigeButton.Visible then
-- change the 'ScreenGui.Frame' to the actual name of your ScreenGui and the Frame (or it can be TextLabel or ImageLabel etc)
player.PlayerGui.ScreenGuiRB.PrestigeButton.Visible = true
end
end
end
end)
This is the code in the GUI
local player = game.Players.LocalPlayer
local PrestigeButton = script.Parent.PrestigeButton
local replicatedStorage = game:WaitForChild("ReplicatedStorage")
PrestigeButton.MouseButton1Up:Connect(function()
replicatedStorage.Prestige:InvokeServer()
end)