What do you want to achieve? We have a block after pressing “E” after 10 seconds it is deleted, and then we respawn again, and “Press E” appears again and so on in a cycle
What is the issue? I have a block but no “Press e”
if workspace:FindFirstChild(Part) == nil then
print("Me spawn you again")
Part:Clone().Parent = workspace
Part.ProximityPrompt.Triggered:Clone().Parent = Part
What solutions have you tried so far? I found the answer to the block but not to “Press E”
local UserInputService = game:GetService("UserInputService")
-- define a function to handle the key press event
local function onKeyPress(input, gameProcessedEvent)
if input.KeyCode == Enum.KeyCode.E then
print("The 'E' key was pressed!")
end
end
-- connect the function to the key press event
UserInputService.InputBegan:Connect(onKeyPress)
You put Part.ProximityPrompt.Triggered:Clone(), .Triggered is an event when the player interacts with the prompt for the required time, and make it like this Part.ProximityPrompt:Clone().Parent = part
local UserInputService = game:GetService("UserInputService")
local Part = script.Parent
Part.ProximityPrompt.Triggered:Clone(), .Triggere
local function onKeyPress(input, gameProcessedEvent)
if input.KeyCode == Enum.KeyCode.E then
print("The 'E' key was pressed!")
end
end
script.Parent.ProximityPrompt.Triggered:Connect(onKeyPress)
UserInputService.InputBegan:Connect(onKeyPress)
--like This?
local UserInputService = game:GetService("UserInputService")
local Part = script.Parent
Part.ProximityPrompt.Triggered:Connect(function(player)
print("The 'E' key was pressed!")
end)
--Never worked with local scripts
script.Parent.ProximityPrompt.Triggered:Connect()
UserInputService.InputBegan:Connect()
This line means, when the proximityprompt (which is a child of Part) fires the event called “Triggered”, then do:
The triggered event returns a parameter(namely, the player who triggered it).
You could change the print to
print(player.Name … " triggered the ProximityPrompt.")
Guys, a very simple solution (For Wii Lifehack) if you want to save the whole object with all the scripts, then just use this command
сopy original part
local Part = script.Parent
local UseE = Part.ProximityPrompt
local obj = Part:Clone()
script
UseE.Triggered:Connect(function(player)
Part:Destroy()
wait(2)
obj.Parent = game.Workspace
all script (if you need)
local Part = script.Parent
local UseE = Part.ProximityPrompt
local Color = Part.BrickColor
local obj = Part:Clone()
UseE.Triggered:Connect(function(player)
Part.BrickColor = BrickColor.new(122)
wait(2)
Part.BrickColor = BrickColor.new(14)
if Part.BrickColor == BrickColor.new(14) then
Part:Destroy()
wait(2)
obj.Parent = game.Workspace
end
end)