I understand I'll be using the Touched Event, as well as the TouchEnded Event. I'm also quite sure I'll be using the delay function of Lua. Here's my pathetic attempt,
--In a Local Script in StarterPack
local plr = game:GetService("Players").LocalPlayer
local Spawn = game:GetService("Workspace"):WaitForChild("Spawn")
local Platform = Spawn:WaitForChild("StartPlatform")
local IsTouching = false
function returntime(timewaited)
print("Waited")
IsTouching = false
end
Platform.Touched:connect(function(part)
if not part or not part.Parent:FindFirstChild("Humanoid") or not part.Parent.Name == plr.Name or IsTouching then return end--if IsTouching = false then
IsTouching = true
Platform.BrickColor = BrickColor.new(math.random(),math.random(),math.random())
end)
Platform.TouchEnded:connect(function(part)
if not part or not part.Parent:FindFirstChild("Humanoid") or not part.Parent.Name == plr.Name then return end
delay(0.5, returntime)
end)
FE is on btw
A lot of the script is just checking if the object that touched the brick is the Local Player's character.
I want the brick to change colors when the player falls on the platform. If the platform changes colors when the player simply walks on the brick, that would simply not do.
I'm trying to think of other ways of explaining my question, but I can't seem to simplify this any further.
Comment if you need a question asked about my situation.
- Testing Dank Bullet
Thank you.
With help from Sporkyz, I came to the following solution,
local plr = game:GetService("Players").LocalPlayer
local char = plr.Character or plr.CharacterAdded:wait()
local hum = char:WaitForChild("Humanoid")
local Spawn = game:GetService("Workspace"):WaitForChild("Spawn")
local Platform = Spawn:WaitForChild("StartPlatform")
local IsTouching = false
local Debounce = false
Platform.Touched:connect(function(part)
if not part or not part.Parent:FindFirstChild("Humanoid") or not part.Parent.Name == plr.Name or IsTouching then return end--if IsTouching = true then
IsTouching = true
Platform.BrickColor = BrickColor.new(math.random(),math.random(),math.random())
end)
hum.FreeFalling:connect(function()
if Debounce then return end
Debounce = true
IsTouching = false
wait(1)
Debounce = false
end)
Works like a charm. However, if this could be simplified, please let me know.
Thanks again.
