Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I make the Fading Brick Local?

local debounce = true
script.Parent.Touched:Connect(function(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if player and hit.Parent:FindFirstChild("Humanoid") then
		if debounce then
			debounce = false
		while script.Parent.Transparency <= 1 do 
			script.Parent.Transparency = script.Parent.Transparency + 0.01
			wait(0.01)
		end
		script.Parent.CanCollide = false
		wait(3)
		script.Parent.CanCollide = true
		script.Parent.Transparency = 0
		debounce = true
		end
	end
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.

3 answers

There is something called StarterPlayerScripts in StarterPlayer, put a local script in there and check if the brick is touched from there.

local Bricks = workspace.Bricks:GetChildren()
local debounce = true

for i,v in ipairs(Bricks) do
	v.Touched:Connect(function(hit)
	    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	    if player and hit.Parent:FindFirstChild("Humanoid") then
	        if debounce then
	            debounce = false
	        while v.Transparency <= 1 do 
	            v.Transparency = v.Transparency + 0.01
	            wait(0.01)
	        end
	        v.CanCollide = false
	        wait(3)
	        v.CanCollide = true
	        v.Transparency = 0
	        debounce = true
	        end
	    end
	end)
end

17 comments

0

FOR SAKE U CANT GET PLAYER WITH :GETPLAYERFROMCHARACTER This is a local script ok? also you are right the local script should be parented to something related to the player

0

There will be multiple bricks, am I right?

0

Tnt yes you can

0

You don't want to put so many scripts for each brick

0

But then again you could use a for loop

0

You absolutely right, I didn't account for that I'll post another.

0

There, now it's fixed.

0

I normally don't use ipairs, I just use pairs

0

And if you change the script.Parent s to v then ill accept your answer

0

LOL i'm stupid

0

hm its still not local

0

What isn't

0

the fading

0

The fading isn't working?

0

Bruh I thought the fading worked so I didn't touch that part

0

The fading works fine, I just checked the script

0

Yeah, the fading is local

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:

local debounce = true
script.Parent.Touched:Connect(function(hit)
    local player = game.Players.LocalPlayer
    if hit.Parent:FindFirstChild("Humanoid")  then
        if debounce then
            debounce = false
        while script.Parent.Transparency <= 1 do 
            script.Parent.Transparency = script.Parent.Transparency + 0.01
            wait(0.01)
        end
        script.Parent.CanCollide = false
        wait(3)
        script.Parent.CanCollide = true
        script.Parent.Transparency = 0
        debounce = true
        end
    end
end)

4 comments

0

bruh local scripts cant get players from :GetPlayer , They need to use local player option

0

sorry, it's been a while since I've opened roblox studio, lemme change it

0

Doesn't seem to work

0

look at TNTIsLyfe's answer

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

local debounce = true
script.Parent.Touched:Connect(function()
    local player = game.Players.LocalPlayer
   
        if debounce then
            debounce = false
        
        script.Parent.CanCollide = false
        wait(3)
        script.Parent.CanCollide = true
        script.Parent.Transparency = 0
        debounce = true
while script.Parent.Transparency <= 1 do 
            script.Parent.Transparency = script.Parent.Transparency + 0.01
            wait(0.01)
        end
    end
end)

6 comments

0

BTW u should also parent the local script to something related to the player so it can detect who the local player is or else it may not work

0

But if you parent this script in a player-related object then it will detect the touched event there

0

then use game.Workspace to select the part

0

But I don't want to make an event for every brick right?

0

they can all fire the same remote event and take some parameters

0

Tnt you can use :GetPlayerFromCharacter in a local script

This discussion is preserved as it was. New answers, comments, and votes are closed.