Turning a local script into a function

Would really like to work out how to turn this script

into a function that updates the StringValue inside of player PetInventory server side
I can get the my pet to show up client side easily but won’t fire the server to let them know I have the pet.
i’m thinking a remote event since this is held inside a LocalScript inside a Gui

please help :frowning:

1 Like

Did i understand right, that you nead some way of updating that value with server event?
If i did then its easy, just make script react to event and read values that event is carying and then set up values.

Sorry for broken English…

you did read it right I need help with how to make a server event inside a local-script that changes the value of the player in server…

im new to server-events can I get a hint where to start the script?

There is a tutorial on remote events

1 Like

game.ReplicatedStorage.Revent.OnClientEvent:Connect(function(values)

petVal.Value=values

end)
Change Revent to event name and (values) to what you want

OnServerEvent not a valid member of folder?

i got bit confused with server event… its client…

I’ve read into remote events Client > Server before but still not following how to do it with this kind of script.

still get the same error that its not part of a folder, am I missing a local file

My English is too poor, i cant explain it…

1 Like

it was in the right direction though, it felt like it could of worked I’ll keep trying to mess around with your script.

You have 2 wrong things

1, you are trying to connect OnServerEvent at folder, change to RemoteEvent.OnServerEvent

2, OnServerEvent:Connect, call it from server script (nomal script), RemoteEvent:FireServer(some value) call from client (localscript).

(you have to create RemoteEvent)

Where did yo put event? It must be in ReplicatedStorage.
RemoteEvent

but if I put the script inside rep storage I can connect it to a local script?

I gave you part of local script, i gave you stuff to put in local script, you nead difrent settup for server script service.

Server funtcions
game.ReplicatedStorage.Revent:FireClient(player,values)

game.ReplicatedStorage.Revent:FireAllClients(values)

game.ReplicatedStorage.Revent.OnServerEvent:Connect(function(player,values)

Server code (Script)

local Event = Instance.new("RemoteEvent",game.ReplicatedStorage)
Event.Name = "SomeEvent"
Event.OnServerEvent:Connect(function(Value)
  print("Value recived from client:",Value)
end)

Client code (LocalScript):

local Event = game.ReplicatedStorage.SomeEvent
Event:FireServer("This is string send by client")
2 Likes

Oops, Server code is wrong

correct one:

local Event = Instance.new("RemoteEvent",game.ReplicatedStorage)
Event.Name = "SomeEvent"
Event.OnServerEvent:Connect(function(Player,Value)
  print("Value recived from client, Player:",Player.Name,"Value:",Value)
end)
1 Like

alright ima sit down and try to edit this thank you for taking your time and writing this out! I’m kind of following what you did and how to proceed hopefully this works