#[SOLVED] How would i assign a value of a variable based on a value inside another script?

1 messages · Page 1 of 1 (latest)

grave finch
#

I have an ID-based system, wehre each weapon has its own ID, and inside of a module script, each gun has a different damage, reloadtime based on its id.

for example:

    
    ID = 1,
    
    ANIMATION = X,
    
    BODY_DAMAGE = 75,
    HEAD_DAMAGE = 100
}```

and inside another script, where you control the weapon, i dont want to make the script extremely long using this for an example:

if EQUIPPED_GUN_ID = 1 then
function
end

if EQUIPPED_GUN_ID = 2 then
other function
end


I hope you get what i mean by this, if not i will try to explain better.
#

btw if you could also tell me how to make a code block instead of individual code lines it would be great

dawn grail
#

For code block use to say:

print("hello world")

#

change lua to any other language to change language

#

For moving values, you can use remote events

grave finch
silent spruceBOT
#

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

dawn grail
#

on one script, you can call the event and pass on the value
one the other script, you can connect a function that fires whenever the event is called and the value read.

#

additionally, are you communicating between a local script and a script, or a local script and local script?

#

Oh and in case I'm not online, you would need to:

local script to local script: fireServer remote event, set up script on serverScripts to receive, and fire the event again back to client (fireClient)

local script to server: fireServer remote event.

Basic code for firing to the server:

event:FireClient(value)

Basic code for receiving on server:

event.OnServerEvent:Connect(function(value)
  -- code here
end)

Basic code for firing to client:

event:FireServer(value)

Basic code for receiving on client:

event.OnClientEvent:Connect(function(value)
  -- code here
end)

Note: value is what you are sending/receiving.

#

In the "code here" areas, add code you want to execute whenever the value is received.

Hope this helps! Good luck! Doublethumbs

grave finch
#

am back

#

sorry i took a shower

#

imma just look over what you said rq

grave finch
# dawn grail Oh and in case I'm not online, you would need to: local script to local script:...

I am working with events already, since im using raycasts to determine the hit.

it wouldnt really be hard if it werent for the fact that sometimes the event value passing
(
||```
Local Script

EVENT:FireServer(VALUE_1, VALUE_2, VALUE_3, VALUE_4)


Server Script

EVENT.OnClientEvent:Connect(function(VALUE_1, VALUE_2, VALUE_3, VALUE_4)

print(VALUE_4))

end)

```*output*

VALUE_3```||
)

is pretty bad and sometimes the value is switched with another value from the values i passed
dawn grail
grave finch
#

Ok, thanks, I will try it right now

#

This is VERY weird

#

I will let you on this info

#

in my Local script where i called FireServer i have a value called RAYCAST, which is what it results when you print a raycast.
if i say print(RAYCAST) inside of the local script it prints the raycasts result, but if i print it from the server script it returns nil

dawn grail
#

Hmm

#

I suggest looking at how the remote event passing along parameters. Correct me if I’m wrong, but raycast creates a table. The table when sent through a remote event will cause it to squash and go wonky, making it unviewable

#

I suggest passing along Vector3s through instead, or passing along the raw x,y,z

grave finch
#

What i need is not a position, orientation, or any kind of localisation. What i need is the part that is hit.

#

Now I have RAY_RESULT which is RAYCAST.Instance.Parent

#

OOOOHHHHHH

#

I know what to do

#

I should have put RAY_RESULT to RAYCAST.Instance

dawn grail
#

If it works for you, here you go!

grave finch
#

Thank you!

dawn grail
# grave finch Thank you!

Of course, you should also rename the title to (SOLVED) [title here] to elt everyone know you've got what you need Thumbs