Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make the Fading Brick Local?

Asked by 4 years ago
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

Log in to vote
1
Answered by
birds3345 177
4 years ago
Edited 4 years ago

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
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 TNTIsLyfe 152 — 4y
0
There will be multiple bricks, am I right? CrypxticDoge 135 — 4y
0
Tnt yes you can birds3345 177 — 4y
0
You don't want to put so many scripts for each brick CrypxticDoge 135 — 4y
View all comments (13 more)
0
But then again you could use a for loop CrypxticDoge 135 — 4y
0
You absolutely right, I didn't account for that I'll post another. birds3345 177 — 4y
0
There, now it's fixed. birds3345 177 — 4y
0
I normally don't use ipairs, I just use pairs CrypxticDoge 135 — 4y
0
And if you change the script.Parent s to v then ill accept your answer CrypxticDoge 135 — 4y
0
LOL i'm stupid birds3345 177 — 4y
0
hm its still not local CrypxticDoge 135 — 4y
0
What isn't birds3345 177 — 4y
0
the fading CrypxticDoge 135 — 4y
0
The fading isn't working? birds3345 177 — 4y
0
Bruh I thought the fading worked so I didn't touch that part birds3345 177 — 4y
0
The fading works fine, I just checked the script birds3345 177 — 4y
0
Yeah, the fading is local birds3345 177 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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)
0
bruh local scripts cant get players from :GetPlayer , They need to use local player option TNTIsLyfe 152 — 4y
0
sorry, it's been a while since I've opened roblox studio, lemme change it jediplocoon 877 — 4y
0
Doesn't seem to work CrypxticDoge 135 — 4y
0
look at TNTIsLyfe's answer jediplocoon 877 — 4y
Log in to vote
0
Answered by
TNTIsLyfe 152
4 years ago

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)

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 TNTIsLyfe 152 — 4y
0
But if you parent this script in a player-related object then it will detect the touched event there CrypxticDoge 135 — 4y
0
then use game.Workspace to select the part TNTIsLyfe 152 — 4y
0
But I don't want to make an event for every brick right? CrypxticDoge 135 — 4y
View all comments (2 more)
0
they can all fire the same remote event and take some parameters yumaking 78 — 4y
0
Tnt you can use :GetPlayerFromCharacter in a local script birds3345 177 — 4y

Answer this question