01 | local debounce = true |
02 | script.Parent.Touched:Connect( function (hit) |
03 | local player = game.Players:GetPlayerFromCharacter(hit.Parent) |
04 | if player and hit.Parent:FindFirstChild( "Humanoid" ) then |
05 | if debounce then |
06 | debounce = false |
07 | while script.Parent.Transparency < = 1 do |
08 | script.Parent.Transparency = script.Parent.Transparency + 0.01 |
09 | wait( 0.01 ) |
10 | end |
11 | script.Parent.CanCollide = false |
12 | wait( 3 ) |
13 | script.Parent.CanCollide = true |
14 | script.Parent.Transparency = 0 |
15 | debounce = true |
16 | end |
17 | end |
18 | end ) |
Local scripts don't work in workspace, so you can't put this script in there. I can't seem to find any idea to solve it.
There is something called StarterPlayerScripts in StarterPlayer, put a local script in there and check if the brick is touched from there.
01 | local Bricks = workspace.Bricks:GetChildren() |
02 | local debounce = true |
03 |
04 | for i,v in ipairs (Bricks) do |
05 | v.Touched:Connect( function (hit) |
06 | local player = game.Players:GetPlayerFromCharacter(hit.Parent) |
07 | if player and hit.Parent:FindFirstChild( "Humanoid" ) then |
08 | if debounce then |
09 | debounce = false |
10 | while v.Transparency < = 1 do |
11 | v.Transparency = v.Transparency + 0.01 |
12 | wait( 0.01 ) |
13 | end |
14 | v.CanCollide = false |
15 | wait( 3 ) |
I'm fairly sure you can put local scripts in the workspace, if you are trying to detect if just the local player touches it, you would have to modify it a bit, perhaps like this:
01 | local debounce = true |
02 | script.Parent.Touched:Connect( function (hit) |
03 | local player = game.Players.LocalPlayer |
04 | if hit.Parent:FindFirstChild( "Humanoid" ) then |
05 | if debounce then |
06 | debounce = false |
07 | while script.Parent.Transparency < = 1 do |
08 | script.Parent.Transparency = script.Parent.Transparency + 0.01 |
09 | wait( 0.01 ) |
10 | end |
11 | script.Parent.CanCollide = false |
12 | wait( 3 ) |
13 | script.Parent.CanCollide = true |
14 | script.Parent.Transparency = 0 |
15 | debounce = true |
16 | end |
17 | end |
18 | end ) |
The reason ur script doesnt work because local scripts dont use :GetPlayerFromCharacter() There are some other bugs but ill give u the fixed script for u that will work in workspace
01 | local debounce = true |
02 | script.Parent.Touched:Connect( function () |
03 | local player = game.Players.LocalPlayer |
04 |
05 | if debounce then |
06 | debounce = false |
07 |
08 | script.Parent.CanCollide = false |
09 | wait( 3 ) |
10 | script.Parent.CanCollide = true |
11 | script.Parent.Transparency = 0 |
12 | debounce = true |
13 | while script.Parent.Transparency < = 1 do |
14 | script.Parent.Transparency = script.Parent.Transparency + 0.01 |
15 | wait( 0.01 ) |
16 | end |
17 | end |
18 | end ) |