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

Have bollards for a gate in FE, how would I fix?

function hello(mode)
	if mode == "Retract" then
		game.Workspace.RoadBlock.PopOne.Transparency = 1
		game.Workspace.RoadBlock.PopTwo.Transparency = 1
		game.Workspace.RoadBlock.PopThree.Transparency = 1
		game.Workspace.RoadBlock.PopFour.Transparency = 1
		game.Workspace.RoadBlock.PopFive.Transparency = 1
		game.Workspace.RoadBlock.PopSix.Transparency = 1
		game.Workspace.RoadBlock.PopOne.CanCollide = false
		game.Workspace.RoadBlock.PopTwo.CanCollide = false
		game.Workspace.RoadBlock.PopThree.CanCollide = false
		game.Workspace.RoadBlock.PopFour.CanCollide = false
		game.Workspace.RoadBlock.PopFive.CanCollide = false
		game.Workspace.RoadBlock.PopSix.CanCollide = false
	elseif mode == "Deploy" then
		game.Workspace.RoadBlock.PopOne.Transparency = 0
		game.Workspace.RoadBlock.PopTwo.Transparency = 0
		game.Workspace.RoadBlock.PopThree.Transparency = 0
		game.Workspace.RoadBlock.PopFour.Transparency = 0
		game.Workspace.RoadBlock.PopFive.Transparency = 0
		game.Workspace.RoadBlock.PopSix.Transparency = 0
		game.Workspace.RoadBlock.PopOne.CanCollide = true
		game.Workspace.RoadBlock.PopTwo.CanCollide = true
		game.Workspace.RoadBlock.PopThree.CanCollide = true
		game.Workspace.RoadBlock.PopFour.CanCollide = true
		game.Workspace.RoadBlock.PopFive.CanCollide = true
		game.Workspace.RoadBlock.PopSix.CanCollide = true
		end
end

game.ReplicatedStorage.Bollards.OnServerEvent:connect(hello)

Tried lots of things, and it didn't work. All of the 'pops' are unions of bollards. Script is in ServerScriptService, remoteevent named Bollards is in replicatedstorage.

Tried firing it.

game.ReplicatedStorage.Bollards:FireServer("Deploy")
game.ReplicatedStorage.Bollards:FireServer("Retract")

Both won't work. Any ideas?

1 comment

0

You might want to put all of those "PopOne" through "PopSix" in a table so you can just loop through all of them to set the Transparancy and CanCollide properties. And you can at least make a variable for "game.Workspace.RoadBlock".

1 answer

✓ Accepted answer
game.ReplicatedStorage.Bollards.OnServerEvent:Connect(function(player, mode) -- first argument on `OnServerEvent`'s are always the player that fired the server
for k, v in ipairs(workspace.RoadBlock:GetChildren()) do -- shorten your script by using a for loop instead
    	if mode == "Retract" then
		v.Transparency = 1
		v.CanCollide = false
	elseif mode == "Deploy" then
        	v.Transparency = 0
		v.CanCollide = true
		end
        end
end

1 comment

1

Nope. its fired from a localscript. Testing.

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