#surfacegui button to open a door

1 messages · Page 1 of 1 (latest)

summer wyvern
#

how do i get the button on a surfacegui on a part to do things in workspace? is it just the same as it would be inside a normal script?

mine looks like this
StarterGui > SurfaceGui > TextButton (adornee is part in workspace)

tidal fjord
#

what do you mean?

summer wyvern
slender ivy
#

It’s the same as if it was a normal local script

summer wyvern
harsh pagoda
slender ivy
#

Textbutton.activated

harsh pagoda
#

Yeah so just use a remote

slender ivy
harsh pagoda
#

transfer the information back to the server through a remote to activate the door

tidal fjord
summer wyvern
harsh pagoda
#

aye

summer wyvern
#

aight

#

thanks yall

harsh pagoda
#

you're welcome

#

glad we could help

slender ivy
tidal fjord
tidal fjord
#

which is better

slender ivy
#

What I do is have an open and close attribute and I render the door based off that attribute to all clients

harsh pagoda
#

so just do it on client only

slender ivy
#

The problem with fireall clients is late joins

#

Attribute method is better

summer wyvern
#

i want it for every player

harsh pagoda
#

so you just send it via remotes to all clients

summer wyvern
#

fireallclients right?

#

sorry im kinda a beginner

harsh pagoda
#

yeah

summer wyvern
#

i forgot everyhing i learned 2 yrs ago

harsh pagoda
#

wait let me check

tidal fjord
summer wyvern
tidal fjord
#

then u wanna open some door

#

so u use remotes to fire server and door which u want to open

slender ivy
tidal fjord
#

also u should make client listener to that door attribute on changed or what called

harsh pagoda
#

just make a listener script

#

yeah exactly

slender ivy
#

Use collection service

#

It’s easiest way

summer wyvern
#

ooh

#

okay

slender ivy
#

I use sleitnicks component system

#

Makes things easy

tidal fjord
#

it's bad

summer wyvern
tidal fjord
#

u cant see them on client I think

slender ivy
#

Yes

#

Tags for initialization

#

Not for changes

#

But tags replicate

tidal fjord
#

oh wait u cant change it on client but can read

#

ok

tidal fjord
#

didnt use collection service since idk 😔

slender ivy
#

Tags replicate but it’s just bad practice

wooden hare
#

similarly to having any buttons do something

slender ivy
#

To listen for tags for replication

summer wyvern
tidal fjord
#

tags can be replaced with classes

summer wyvern
#

people here said its only client sided

slender ivy
#

Tags should be used

slender ivy
#

Tags mark an object

tidal fjord
slender ivy
summer wyvern
#

collectionservice:gettagged?

harsh pagoda
slender ivy
slender ivy
harsh pagoda
#

Neat thanks dmed

slender ivy
summer wyvern
#

isnt that just a waitforchild tho

#

so i fire the remote to the server in a localscript in the button then a serverscript listens to it with Onserverevent and tags them and it does whatever right

slender ivy
summer wyvern
# slender ivy No
-- ServerScript (ServerScriptService)
local remote = Instance.new("RemoteEvent")
remote.Name = "ToggleDoorEvent"
remote.Parent = game.ReplicatedStorage

local CollectionService = game:GetService("CollectionService")
local Players = game:GetService("Players")

-- store cooldown per player
local cooldowns = {}

remote.OnServerEvent:Connect(function(player)
    if cooldowns[player] and tick() - cooldowns[player] < 15 then
        return -- still need to wait
    end
    cooldowns[player] = tick()

    local doors = CollectionService:GetTagged("Door")
    for _, door in ipairs(doors) do
        if door:GetAttribute("IsOpen") then
            door:SetAttribute("IsOpen", false)
            print(door.Name.." closed")
        else
            door:SetAttribute("IsOpen", true)
            print(door.Name.." opened")
        end
    end
end)

soo kinda like this?
this is ai code im just tryna understand it, couldnt really finda tutorial for these

#

ignore the instance.new remote event part idk why it did that

summer wyvern
#

i just have to tag the doors but i can do that manually

tidal fjord
#

you could make smth like this I tried to make it easy to understand for u

#
local yourDoor = nil -- path to your door or smth instead of nil

local RS = game:GetService('ReplicatedStorage')

script.Parent.Activated:Connect(function()
    RS.DoorInteract:FireServer(yourDoor)
end)
#

this is your client side

#

idk your lvl so I made js 1 script in button

#
local RS = game:GetService('ReplicatedStorage')

RS.DoorInteract.OnServerEvent:Connect(function(player: Player, Door: Part | Model)
    -- you can insert logic like player openned the door and do like omg global msg
    
    for i, loopPlayer in game:GetService('Players'):GetPlayers() do
        -- some event fires on player for activating this door so it's changed there
    end
    
    Door:SetAttribute('Openned', true) -- you can play with this if u wanna open / close 
end)
#

then u make script on server

tidal fjord
summer wyvern
#

the thing is i do

summer wyvern
#

it looks clean tho

#

ty

summer wyvern
tidal fjord
#

convenience, beauty

summer wyvern
#

i get it now tho

#

so it goes through all the players and does it locally for them too

#

instead of on the serv

#

so if i want it to be a toggle then i just

if isopen then
Door:SetAttribute("opened,false)
else
Door:SetAttribute("opened",true)
end```
tidal fjord
summer wyvern
#
Door:SetAttribute('Openned', true) -- you can play with this if u wanna open / close   
        -- some event fires on player for activating this door so it's changed there  
    end  
      
    
end)```
also its like this right?
summer wyvern
#

if its false then turns it to true

#

and the other way around

#

?

tidal fjord
#

if bool is nil or false its true after

#

if true then false

#
RS.DoorInteract.OnServerEvent:Connect(function(player: Player, Door: Part | Model)
    -- you can insert logic like player openned the door and do like omg global msg
    
    local Bool = Door:GetAttribute('Openned')
    
    Door:SetAttribute('Openned', not Bool)
    
    for i, loopPlayer in game:GetService('Players'):GetPlayers() do
        -- some event fires on player for activating this door so it's changed there
        
        SomeOpenEventOnClient:FireClient(loopPlayer, Bool)
    end
end)
tidal fjord
summer wyvern
#

and what is the someopeneventonclient

tidal fjord
summer wyvern
#

okay

#

ill get it sometime

#

eventually

#
local button = script.Parent
local RS = game:GetService("ReplicatedStorage")
local doorRemote = RS:WaitForChild("DoorInteract")
local yourDoor = workspace:WaitForChild("Door1") 

button.Activated:Connect(function()
    doorRemote:FireServer(yourDoor)
end)
local RS = game:GetService("ReplicatedStorage")
local doorRemote = RS:WaitForChild("DoorInteract")

doorRemote.OnServerEvent:Connect(function(player: Player, Door: Part | Model)
    local Bool = Door:GetAttribute("Openned")
    Door:SetAttribute("Openned", not Bool)

    if Door:GetAttribute("Openned") then
        Door.BrickColor = BrickColor.new("grkeen")
    else
        Door.BrickColor = BrickColor.new("red")
    end
end)
tired linden
#

"grkeen"

fierce trout
#

button in surfacegui only works in the client

summer wyvern
#

bro whats wrong

fierce trout
vivid ruin
#

promixitypromt

vivid ruin
summer wyvern