#How to make a table from a server script accessible in a local script

1 messages · Page 1 of 1 (latest)

fiery jetty
#

I'm still trying to figure out a way to add parts with a specific tag to a raycast exclusion list. There is a part that is cloned upon a player joining in a script within ServerScriptService, which is given the tag of "Cursor" since it will follow the player's mouse to act as a cursor visualizer. However, the local script that calculates the player's cursor position in a 3D space will still collide with the cursor part, which causes it to fly towards the camera. I need to find a way to get the tag of the object into the local script, so I can input it into the raycast filter and have it be excluded.

#

it works from the server script but not the local script

harsh shadow
fiery jetty
#

because it's not being excluded by the raycast, the raycast hits it and causes it to update its position onto itself

#

though someone else mentioned that i could just add the cloned part to a table and see if i could just exclude the contents within the table as a whole

#

only issue is that the local script is unable to access the table within the server script

#

I figured i could use a remote event for it but im not sure how to transfer a table via a remote event

#

How to make a table from a server script accessible in a local script

harsh shadow
fiery jetty
#

yeah i suspected that. only issue is what i was trying to do was yielding no results

#

basically, table name is passed as parameter

#

but then trying to do anything with that in the local script wouldnt give me anything

harsh shadow
#

wdym? You mean like there is no arguments being passed?

fiery jetty
#

lemme try passing the table into the local script via a remote event again cuz theres a good chance i was doing it wrong

#

i likely did this wrong

#

but i tried to make a variable out of the table passed from the server script, and then looping and printing to make sure it was actually getting the contents

#

but the loop yielded nothing as v is apparently nil

harsh shadow
#

outside of the function

#

actually the for loop has to be inside the event

#

because there is no variable called getCursorTable when you call the for loop

harsh shadow
# fiery jetty

when you are using fire client, you need to have the player recipient as the first argument

#

then your additional arguments after

fiery jetty
harsh shadow
#

yeah so probably put that line into the event when you called the server

#

and pass the player argument that you received

fiery jetty
#

ok, so no issue on the client's end. now its the server

#

unable to cast value to object

#

the thing is, cursorTable is a table (line 4)

#

so idk why its not passing through correctly

harsh shadow
#

so you need the player

#

ohhh

#

that makes it more simpler

#

that should work

fiery jetty
harsh shadow
#

the event might have not been loaded on the client

#

so you have to use waitforchild

#

for the event

fiery jetty
#

so....where would i put that exactly?

#

can i make the RaycastExcludeMousePart wait for child??

harsh shadow
#

yes you wait for the event to load using WaitForChild

#

something like game.ReplicatedStorage:WaitForChild( event name here)...

fiery jetty
#

yeah im clearly just doing this wrong lol

harsh shadow
#

oh you have to wait for the RaycastExcludeMousePart

fiery jetty
#

i hate that i basically have to have my hand held when writing this stuff out cuz i keep somehow screwing up basic instructions

harsh shadow
uncut pewterBOT
#

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

harsh shadow
#

i think it would be best if you were to keep scripting to watch tutorials or do mini side projects

#

to help with understanding

fiery jetty
fiery jetty
#

cuz i will search for like 20 minutes on google or roblox studio forum posts before making one here myself

harsh shadow
#

WaitForChild(" {string here} ")

#

you just need to close the string with a parenthesis

fiery jetty
#

oh

#

the console should output "iDrizzyB's mousePart," as that exact same code nested within the server script works as intended and outputs that

harsh shadow
fiery jetty
#

lemme try

harsh shadow
#

ah you commented the variable but it doesnt matter

#

you can use the cursorTable variable instead of the getCursorTable in the loop

vague cove
#

why do you need this on the server exactly?

fiery jetty
fiery jetty
vague cove
#

i'm guessing you're trying to move this mousepart to follow the player's mouse and show for all players?

uncut pewterBOT
#

studio** You are now Level 7! **studio

harsh shadow
vague cove
# fiery jetty correct

where are you setting position? i see a bit of this render() function that looks like it has mouse ray stuff in it, can you show this function?

harsh shadow
vague cove
fiery jetty
vague cove
#

so really what the problem is you are having a hard time getting a reference to this object on the client for mouse ray

fiery jetty
fiery jetty
fiery jetty
fiery jetty
vague cove
# fiery jetty the thing is, ``cursorTable`` is a table (line 4)

the thing about doing this in PlayerAdded is that the part is being cloned at the same time as you are firing it to the client, it is unlikely for the part to exist on the client yet (thus it will be nil) and also unlikely for that event to be connected on the client when you fire it, so it's a 2-fold problem there. personally, the simplest way I would do it is to use an ObjectValue set to point to this cursor, or on the client you can workspace:WaitForChild(LocalPlayer.Name .. "'s mousePart") for example

fiery jetty
#

alright, i'll try that

#

alright, so the wait for child thing did yield a result on the client's end

#

but, what's this ObjectValue thing? never heard of it before

vague cove
fiery jetty
#

i'll make sure to read the documentation on pointers then, since i've never heard of that either☠️

vague cove
#

you can set the value on the server and this will replicate to client when the client receives the instance

fiery jetty
#

ahh

vague cove
fiery jetty
#

so...is it like the tagging thing that comes with collectionService??

vague cove
#

kind-of

#

it doesn't alter the instance in any way

#

objectvalues are good if you need a reference to some arbitrary instance, like your mouse pointer for example

fiery jetty
#

does it bypass the whole local script thing? can it be accessed from multiple scripts?

vague cove
#

coz you can set the value on the server and if not objectvalue.Value then objectvalue:GetPropertyChangedSignal("Value"):Wait() end myinstance=objectvalue.Value

vague cove
fiery jetty
#

ohhhh

#

thats awesome

vague cove
# fiery jetty the thing is, ``cursorTable`` is a table (line 4)

just one thing i would change with this and that is to make the mousepart a model and set its streaming mode to persistentperplayer and add the intended player to it so it is guaranteed to always exist for that player, if it were up to me i'd probably also set network ownership of the part to that player too so the player can move the part directly for themselves, it's not like you're verifying if the client's ray actually hit anything or is a valid ray result

#

exploiter could send any position they wanted for their mouse ray and server says yup okay

fiery jetty
#

oh yikes, alright then

vague cove
fiery jetty
vague cove
#

or, well, you're cloning from something so just make what you're cloning a model

#

then use model:PivotTo(cframe) instead of part.CFrame=...etc

#

but that's just what i would do 🤷

fiery jetty
fiery jetty
vague cove
#

kind-of annoying how you have to detour through a model to get to it but ehh it's not that bad

fiery jetty
#

ah ok

fiery jetty
#

i got the object value working fine

#

but how do i do the pivotto() thing

vague cove
#

because models dont have a position like parts do, they instead inherit their position from their primary part, so you have to use a different method to move it

#

or cframe the primary part

fiery jetty
#

i had a cframe set up for when the mousePart was a solitary part. should i just revert to that

#

cuz this isnt working

#

wait why does the mouse need to be in a model anyways?

fiery jetty
#

ohhh models have access to streamingmode?

vague cove
#

yea can only set it on a model

fiery jetty
#

ohhh.. yeah that is kind-of annoying that you need to detour through a model lol

#

okie dokie

fiery jetty
vague cove
fiery jetty
#

yeah i could be googling some of these, u right....

fiery jetty
#

but i cant anchor a model

#

nvm i see issue

#

i checked while running, turns out the primary part is in fact not anchored