04nv
(04nv)
July 11, 2022, 3:33pm
#22
I edited the script that I originally sent to check for LocalPlayer, and it has a 2 second delay before a button can be pressed again.
1 Like
0xzMq
(Mystery)
July 11, 2022, 3:35pm
#23
04nv:
local players = game:GetService("Players")
local tweenservice = game:GetService("TweenService")
local tweenbuttons = workspace:WaitForChild("TweenButtons")
local notimebuttons = tweenbuttons:WaitForChild("No-TimeButtons")
local timedbuttons = tweenbuttons:WaitForChild("TimedButtons")
local info = TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0)
local notimebuttonsdelay = 2 -- delay until buttons can be used again
local timedbuttonsdelay = 2 -- delay until buttons can be used again
for _, model in pairs(notimebuttons:GetChildren()) do
if model:IsA("Model") then
local button = model:FindFirstChild("Button")
local visibleparts = model:FindFirstChild("VisibleParts")
local tweeningpart = typeof(button) == 'Instance' and button:FindFirstChild("TweeningPart")
if typeof(visibleparts) == 'Instance' and typeof(tweeningpart) == 'Instance' and tweeningpart:IsA("BasePart") then
local down = button:WaitForChild("Down")
local up = button:WaitForChild("Up")
local debounce = false
tweeningpart.Touched:Connect(function(hit)
if debounce ~= true then
debounce = true
local character = hit.Parent
local humanoid = typeof(character) == 'Instance' and character:FindFirstChildWhichIsA("Humanoid")
local player
if typeof(humanoid) == 'Instance' and humanoid:IsA("Humanoid") then
if humanoid.Health <= 0 then
return -- ignore dead players
end
player = players:GetPlayerFromCharacter(character)
end
if typeof(player) == 'Instance' and player:IsA("Player") and player == players.LocalPlayer then -- lol typechecking go brr
tweenservice:Create(tweeningpart, info, {Position = down.Position}):Play()
local press = tweeningpart:FindFirstChild("Press")
if typeof(press) == 'Instance' and press:IsA("Sound") then
press:Play()
end
for _, part in pairs(visibleparts:GetDescendants()) do
if part:IsA("BasePart") then
tweenservice:Create(part, TweenInfo.new(1), {Transparency = 0}):Play()
part.CanCollide = false
end
end
end
task.wait(notimebuttonsdelay)
debounce = false
end
end)
end
end
end
for _, model in pairs(timedbuttons:GetChildren()) do
if model:IsA("Model") then
local timer = model:FindFirstChild("Timer")
local originaltime = typeof(timer) == 'Instance' and timer:IsA("IntValue") and timer.Value
local button = model:FindFirstChild("Button")
local visibleparts = model:FindFirstChild("VisibleParts")
local tweeningpart = typeof(button) == 'Instance' and button:FindFirstChild("TweeningPart")
if typeof(visibleparts) == 'Instance' and typeof(tweeningpart) == 'Instance' and tweeningpart:IsA("BasePart") then
local down = button:WaitForChild("Down")
local up = button:WaitForChild("Up")
local debounce = false
tweeningpart.Touched:Connect(function(hit)
if debounce ~= true then
debounce = true
local character = hit.Parent
local humanoid = typeof(character) == 'Instance' and character:FindFirstChildWhichIsA("Humanoid")
local player
if typeof(humanoid) == 'Instance' and humanoid:IsA("Humanoid") then
if humanoid.Health <= 0 then
return -- ignore dead players
end
player = players:GetPlayerFromCharacter(character)
end
if typeof(player) == 'Instance' and player:IsA("Player") and player == players.LocalPlayer then -- lol typechecking go brr
tweenservice:Create(tweeningpart, info, {Position = down.Position})
local press = tweeningpart:FindFirstChild("Press")
if typeof(press) == 'Instance' and press:IsA("Sound") then
press:Play()
end
for _, part in pairs(visibleparts:GetDescendants()) do
if part:IsA("BasePart") then
part.Transparency = 0
part.CanCollide = true
end
end
local surfacegui = tweeningpart:FindFirstChildWhichIsA("SurfaceGui")
local textlabel = typeof(surfacegui) == 'Instance' and surfacegui:FindFirstChild("TextLabel") or {Text = ''}
while timer.Value > 0 do
task.wait(1)
timer.Value -= 1
textlabel.Text = timer.Value
end
textlabel.Text = '0'
timer.Value = originaltime
tweenservice:Create(tweeningpart, info, {Position = up.Position})
for _, part in pairs(visibleparts:GetDescendants()) do
if part:IsA("BasePart") then
part.Transparency = 1
part.CanCollide = false
end
end
end
task.wait(timedbuttonsdelay)
debounce = false
end
end)
end
end
end
Hol’ up, HOW DID YOU DO THAT? It worked! I will mark this as the solution, thank you so much!
I am curious how did you do that?
04nv
(04nv)
July 11, 2022, 3:36pm
#24
Check if the player is the LocalPlayer when you retrieve it from the Touched signal.
if player == players.LocalPlayer then
-- the player is the game client's LocalPlayer
end
1 Like
0xzMq
(Mystery)
July 11, 2022, 3:37pm
#25
Hm I tried that some minutes before but that did not change anything
1 Like
04nv
(04nv)
July 11, 2022, 3:38pm
#26
Notice how I grab the player, the player is checked simply from the hit part’s parent, you then retrieve it as you did before with GetPlayerFromCharacter
. With the newfound player variable returned from that namecall method, you can check if the player is the LocalPlayer from there.
0xzMq
(Mystery)
July 11, 2022, 3:38pm
#27
Maybe because i just made if player then instead of if player == game.player.localplayer then lol
04nv
(04nv)
July 11, 2022, 3:39pm
#28
I use this quite often it is the best way.
if typeof(player) == 'Instance' and player:IsA("Player") and player == players.LocalPlayer then
end
1 Like