Button don't work when humanoid is die

I create a part when touching which calls the function promptgamepusspurchase and then automatically gives a button when pressed which teleports to the same part, I have everything works except for something, first how can I make it so that gamepass saved after leaving the game and the button remained in place, second how to make it so that after the death of Humanoid button worked?

The video:

The script in the part:

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local debris = game:GetService("Debris")

local spawndonat1 = workspace.Map.SpawnSecretDon.SpawnDonat1

local SpawnButDon = script.Parent.SpawnDonate:Clone()

local gamePassId = 839029956
local spawnPart = script.Parent

local function onTouch(otherPart)
    local character = otherPart.Parent
    if character and character:IsA("Model") then
        local player = Players:GetPlayerFromCharacter(character)
        if player then
			MarketplaceService:PromptGamePassPurchase(player, gamePassId)
			MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(player, gamePassId, waspurchased)
				if gamePassId == 839029956 then
					spawnPart.CanCollide = false
					spawnPart.Transparency = 1
					spawnPart.CanTouch = false
					
					spawndonat1.CanTouch = true
					spawndonat1.CanCollide = true
					spawndonat1.Transparency = 0
					
					SpawnButDon.Parent = player.PlayerGui
				end
			end)
        end
    end
end

spawnPart.Touched:Connect(onTouch)


The localscript in the button:

local ButtonSpawn = script.Parent
local plr = game:GetService("Players")
local char = plr.LocalPlayer.Character

local spawndonat1 = workspace.Map.SpawnSecretDon.SpawnDonat1

ButtonSpawn.MouseButton1Click:Connect(function()
	char.HumanoidRootPart.CFrame = spawndonat1.CFrame + Vector3.new(0, 5, 0)
end)

thank you in advance :slight_smile:```

2 Likes

you can make a script that detects whenever a player joins and get its character

something like:

game.Players.PlayerAdded:Connect(function(Player)
  Player.CharacterAdded:Connect(function(Character)
   if hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, passID) then
--give the tool
    end
  end
end

of course you should fix this

1 Like

I would recommend looking for the option ResetOnSpawn on the ScreenGui, and disable it.

1 Like

I tried this, it didn’t help. I still can’t click the button after death

Well the gamepass should be part of their inventory forever, unless they manually delete it. A Gui can’t be pressed after they die because there is no Gui to push. Was removed when they died.

I don’t totally understand what you’re doing here. I’m assuming once they trigger the button and have the gamepass the button is there for use. So, to bring the button back when they re=spawn would be as easy as checking for the gamepass and if so add the button again.

local ButtonSpawn = script.Parent
local plr = game:GetService("Players")
local Itsyou = plr.LocalPlayer

local spawndonat1 = workspace.Map.SpawnSecretDon.SpawnDonat1

ButtonSpawn.MouseButton1Click:Connect(function()
Itsyou.Character.HumanoidRootPart.CFrame = spawndonat1.CFrame + Vector3.new(0, 5, 0)
end)

There only 1 wrong thing you should not add that outside function if want character keep detected anytime as long your character was here. unless other way with active ResetOnSpawn
vvv

local char = plr.LocalPlayer.Character

can you tell me how to do it? does it have to be done in localscript?

There is nothing wrong with the server side but localscript has one issue. The char value is assigned to player’s character but on death it’ll be destroyed so it’ll be equal to nil.

One of the ways how to deal with the problem is to reassign char value every time a player has clicked the button. Here is the code sample :

local ButtonSpawn = script.Parent
local plr = game:GetService("Players")
local char

local spawndonat1 = workspace.Map.SpawnSecretDon.SpawnDonat1

ButtonSpawn.MouseButton1Down:Connect(function()
	char = plr.LocalPlayer.Character
	char.HumanoidRootPart.CFrame = spawndonat1.CFrame + Vector3.new(0, 5, 0)
end)

or

Enable ResetOnSpawn property in your ScreenGui where the button is descendant of

I hope it will work for you

2 Likes

Thank you it worked, but I have one more question? I want that if a player has a gamepass, then automatically the button is shown when he logs into the game.
I made a script, but when I enter the game, the button does not work and I am not teleported to the specified place.
do you know of any way to fix it?

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local debris = game:GetService("Debris")

local spawndonat1 = workspace.Map.SpawnSecretDon.SpawnDonat

local SpawnButDon = script.Parent.SpawnDonate:Clone()

local gamePassId = 839029956
local spawnPart = script.Parent

local function onTouch(otherPart)
	local character = otherPart.Parent
	if character and character:IsA("Model") then
		local player = Players:GetPlayerFromCharacter(character)
		if player then
			MarketplaceService:PromptGamePassPurchase(player, gamePassId)
			MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(player, gamePassId, waspurchased)
				if gamePassId == 839029956 then
					SpawnButDon.Parent = player.PlayerGui
				end
			end)
		end
	end
end

spawnPart.Touched:Connect(onTouch)

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		if MarketplaceService:UserOwnsGamePassAsync(Player.UserId, gamePassId) then
			SpawnButDon.Parent = Player.PlayerGui
		end
	end)
end)

This one could work. I have prevent some other issue that could happen like the second player who bought the gamepass could not get the button shown on theirs screen. Code sample :

-- Services

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

-- Variables

local spawnPart = script.Parent
local spawnButDon = script.Parent.SpawnDonate

local gamePassIdRequired = 839029956

-- Functions

local function setButtonParent (player)
	if player then
		local buttonCopy = spawnButDon:Clone()
		buttonCopy.Parent = player.PlayerGui or player:WaitForChild("PlayerGui")
	end
end

local function onTouch(part)
	local character = part.Parent
	if character and character:IsA("Model") then
		local player = Players:GetPlayerFromCharacter(character)
		if player then
			MarketplaceService:PromptGamePassPurchase(player, gamePassIdRequired)
		end
	end
end

local function playerJoined (player)
	if MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassIdRequired) then
		setButtonParent(player)
	end
end

local function purchseFinished (player, gamePassId, waspurchased)
	if gamePassId == gamePassIdRequired and waspurchased == true then
		setButtonParent(player)
	end
end

-- Events

spawnPart.Touched:Connect(onTouch)
Players.PlayerAdded:Connect(playerJoined)
MarketplaceService.PromptGamePassPurchaseFinished:Connect(purchseFinished)

image
I’m getting this error

even though the path is correct.
image

Check if there are any other instances named SpawnSecretDon or make sure the part is anchored

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.