Greetings developers!
I am trying to make a part appear when a player has been in the game for about 5-6 minutes. How could I do that?
Greetings developers!
I am trying to make a part appear when a player has been in the game for about 5-6 minutes. How could I do that?
If you want to make the part appear only to that specific player after certain amount of time, you have to be using RemoteEvents and the code should look like this:
( Add a new instance called RemoteEvents inside of ReplicatedStorage )
--script inside of serverscriptservice
game:GetService("Players").PlayerAdded:Connect(function(Player)
while true do
if Character.HumanoidRootPart.Position.Magnitude > 0 then --(line number 1)
InGameTime += 1
end
if InGameTime == 300 or InGameTime == 360 then
game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent"):FireClient()
break
end
task.wait(1)
end
end)
--localscript inside of StarterCharacterScripts or StarterPlayerScripts
game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent").OnClientEvent:Connect(function(Player)
local Part = Instance.new("Part",workspace)
end)
If you want to make the part appear to all players, you can use the following code:
game:GetService("Players").PlayerAdded:Connect(function(Player)
local InGameTime = 0
Player.CharacterAdded:Connect(function(Character)
while true do
if Character.HumanoidRootPart.Position.Magnitude > 0 then --(line number 2)
InGameTime += 1
end
if InGameTIme == 300 then
local Part = Instance.new("Part",workspace)
end
task.wait(1)
end
end)
end)
For line number 1 and line number , you can remove the if statement unless and until you just want the player to just be present in the game irrelevent to the context if he/she is afk or not
I assume I can use my PartName here right?
( sorry for the clearly dumb question )
For a simpler approach to @dragnmer solution, you can simply wait for some amount and check to see if the player exists. If they do, spawn the part.
You can change the identifier’s name as per your desire and comfort. The instance’s name shouldnt be changed
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.