#surfacegui button to open a door
1 messages · Page 1 of 1 (latest)
what do you mean?
for example if the player clicks the button it opens a door with tweenservice
It’s the same as if it was a normal local script
okay thank you
I haven't done those in a long while but aren't they entirely local-sided?
Textbutton.activated
Yeah so just use a remote
^^
transfer the information back to the server through a remote to activate the door
you use local script but it only moves for 1 player
so remote
aye
If you want it to replicate across every client you can tween on the server but it looks bad
if you make game like doors yeah
you can fire server and then fire all clients
which is better
What I do is have an open and close attribute and I render the door based off that attribute to all clients
yeah essentially that's what happens, most of the time the server is going to be at least slightly lagged or have desync issues so there's going to be stutter with the door
so just do it on client only
i want it for every player
so you just send it via remotes to all clients
yeah
i forgot everyhing i learned 2 yrs ago
wait let me check
you can change attributes on server and listen to them on client
never really ever heard of how that works and what that is
for example, u have code that initiates everything so u initiate oppened doors first
then u wanna open some door
so u use remotes to fire server and door which u want to open
Attributes are properties that can be put on parts, you can listen for the change of that attribute in order to open or close a door
oh yeah that's smart
also u should make client listener to that door attribute on changed or what called
i done that in the past, it clicked now
u cant see them on client I think
??
Yes
Tags for initialization
Not for changes
But tags replicate
isnt it just like
didnt use collection service since idk 😔
Tags replicate but it’s just bad practice
To listen for tags for replication
i dont know thats why i asked
tags can be replaced with classes
people here said its only client sided
Tags should be used
how do I get role like u have
collectionservice:gettagged?
speaking of which can i dm you about it
Sure
Yes and you’ll also need to listen for late joins via an event
Neat thanks dmed
wdym
When the script initializes it won’t have every object loaded in yet
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
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
🤨
whats the problem? it looks good to me
i just have to tag the doors but i can do that manually
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
if u wanna interact with lots of doors then u can make class
the thing is i do
Also i dont really get the
(player: Player, Door: Part | Model)
``` what is that
it looks clean tho
ty
its type
oh and whats that for
convenience, beauty
aight
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```
you can do
local Bool = Door:GetAttribute('Openned')
Door:SetAttribute('Openned', not Bool)
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?
what does not bool equal to
if its false then turns it to true
and the other way around
?
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)
also put in this event door that u open
uhm what
and what is the someopeneventonclient
event I made for test
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)
"grkeen"
button in surfacegui only works in the client
"red", "gkreen"
dude
😭
😨
bro whats wrong
red and gkreen are not valid brickcolors, u should use Really red and Lime green instead
promixitypromt
on a part
what
