#Why isn't this code working?

1 messages · Page 1 of 1 (latest)

fiery roost
#

Hey, I'm trying to make the server send messages to the server via a remote event but either the event isn't firing properly or it isn't being caught. Why isn't this working and is there a way to modify this?
The left script is the child of the trigger that sends the event on touch (Child to Trigger)
script.parent is the trigger that's supposed to send the event on touch (In Workspace)
ChatThingy is the remote event (In ReplicatedStorage)
The right script is a local script that tries to catch the message to send the messages (In sterterGUI)
If there are any questions lmk

digital slate
#

local scripts are meant for the client so something like on server event doesn't work

#

on server event is meant for the server and server side scripts

fiery roost
#

So do I change that to a regular script?

frosty hamlet
digital slate
#

but before you do that if the touched event for the part is in a server script then don't bother creating a remote event

#

either make a bindable or copy and paste the on server event code into the touched event

#

you can only fire server from the client

fiery roost
#

What's a bindable

digital slate
#

bindable event basically it allows for server to server or client to client communication so you can have a sever side script that fires it and another that connects the event to some function but you can't do it between server and client because remote events are used for that

glad vineBOT
#

studio** You are now Level 4! **studio

fiery roost
#

Is workspace client or server?

balmy comet
#

Yo

digital slate
#

both

balmy comet
digital slate
#

but for storage usually use replicated storage (that's client and server)

#

brawl dev also good

#

that's how I learned but I also had previous experience in python

fiery roost
#

Also I am fairly fluent in Lua

balmy comet
fiery roost
#

Who?

balmy comet
#

So you just don’t know the Roblox things

fiery roost
#

Yeah

balmy comet
#

You don’t know how server / client stuff works?

fiery roost
#

I understand it runs on LuaU, which is a branch of Lua, I just don't entirely know the difference

fiery roost
frosty hamlet
#

fireserver() is on the client

#

fireclient() is on the server

#

onserverevent() is on the server

#

onclientevent() is on the client

balmy comet
# fiery roost Yea

Server changes replicate to all client

If a visual change occurs on the client it’s only for that client.

If the server changes:
replicated storage
workspace
lighting
… a lot more

It’s going to replicate to every client.
But if the client changes those things, it’s only going to appear for that client

Some things are only visible to one side, for example Serverstorage and ServerScriptService is only visible to the server for security reasons.

StarterPlayer is only visible and accessible on the client

#

For server and client to communicate you use remote events and remote functions.

Remote events are one way triggers from server to client or other way around

Bindable events are like remote events but they’re supposed to be used on one side only for communication between scripts

#

Remote functions are like remote events but they give feedback. For example a remote function firing the client to give the mouse position and the client gives the mouse position back to the server (unsafe)

fiery roost
#

Ohhhh

#

So I should use a bindable event in this case?

balmy comet
#

I didn’t read ur post

fiery roost
#

Trying to send chat messages when a trigger is touched

#

You can just scroll up

balmy comet
#

Print on both triggers and send me a picture of replicated storage

frosty hamlet
balmy comet
fiery roost
#

No it's in a regular script now

frosty hamlet
#

this needs to be a serverscript

#

is it

#

oh

fiery roost
#

Yeah

balmy comet
frosty hamlet
#

so it should work then

fiery roost
#

It's saying FireServer only happens on client

balmy comet
#

Huh

fiery roost
frosty hamlet
#

yeah you need to fireserver on a local script

balmy comet
# fiery roost

The place where you fire server should be a client script

#

Not server script

frosty hamlet
#

this needs to be a localscript

digital slate
#

if the touched event is happening on the server then just grab the code from the on server event script and paste it into the touched event

balmy comet
#

Yeah you could do all of it on client

fiery roost
#

No, the chat messages part can only happen on a server script

frosty hamlet
#

so whats the issue right now

balmy comet
#

Does ur script work yet

fiery roost
#

No

frosty hamlet
#

ddi you turn this into a serverscript

balmy comet
#

Takes pictures of your serverscriptservice starterplayer and replicated storage

#

All expanded out

fiery roost
#

Either I messed up the touch sensing part or the function isn't happening

fiery roost
frosty hamlet
fiery roost
#

Yes

frosty hamlet
#

i shouldve made that clear

digital slate
#

try replacing touched event like this

trigger.Touched:Connect(function()
game.TextChatService.TextChannels.RBXGeneral:DisplaySystemMessage("Test")
end)

balmy comet
#

Bruh

#

It’s because

#

U have a local script in workspace

#

You can’t do that

#

Can you?

digital slate
#

you can if you change the context

balmy comet
#

This is why pictures r needed

digital slate
#

better to put it in starterplayer anyways

fiery roost
#

It isn't properly registering that it's being touched

glad vineBOT
#

studio** You are now Level 5! **studio

balmy comet
#

Read

balmy comet
#

Did u already do what he said

fiery roost
#

Do I just put the part in StarterPlayer?

balmy comet
#

Bruh

#

No

#

The script

digital slate
#

what kind of script is it for the touched event server (script) or client (localscript)

balmy comet
#

😭

balmy comet
#

His script for that is under the part

#

So move the script into starterplayer

digital slate
#

ok now copy and paste the code from that script

balmy comet
#

Reference the part from workspace

digital slate
#

and put inside a server script

fiery roost
#

Ohhhhh

frosty hamlet
#

yall gonna confuse the guy

balmy comet
#

Yeah what

digital slate
#

but keep the server script in workspace or server script service (preferably)

balmy comet
#

Just move the client script gng

#

That’s all

#

Client scripts don’t run under workspace

#

Unless you do that context thing or wtv

#

But might as well have it in the right spot

digital slate
#

actually the server script would need to be a child of that part because the reference to the part is script.Parent

fiery roost
digital slate
#

that's good

#

does it work?

fiery roost
#

Now I can only assume that it isn't registering that it's touched

#

The first image is of the output

digital slate
#

you need to send the entire script not just the touched

#

or the door script

fiery roost
#

No the door script is completely unrelated to this

#

I'm just showing that it isn't doing anything

digital slate
#

i think i figured out what you need to do

put a local script in starter character scripts

then do the following in the script

local TextChatService = game:GetService("TextChatService")

local trigger = workspace:WaitForChild("ChatTrigger")

trigger.Touched:Connect(function()
local robloxGeneral : TextChannel = TextChatService.TextChannels.RBXGeneral
robloxGeneral:DisplaySystemMessage("message")
end)

worldly kestrel
worldly kestrel
#

I don’t recommend storing any scripts into the workspace