From client to server help

so i am making a power thing and i made it on a client script i want it to show on server too but i dont know how to do it i tried with remote events but it didnt work

here is the file Power.rbxl (40.2 KB)

Edit1:forgot to update the file

the script is in starter player scripts

thank you for your help

To communicate from client > server, you should use Remote Events. Here’s some useful links that can help:

Thedevking’s tutorial (I highly recommend watching this and the rest of his tutorials)
Example scripts and some other things

1 Like

What do you want to show up on the server? Also, you aren’t firing the remote event in the damage script, which might be why it isn’t working.

1 Like

no i am trying to make the black hole show i server

Couldn’t you just create the black hole on the server?

i dont think i can use mouse.Hit or mouse.Button1Down on server

Fire remote event when you click to tell the server to create a new part.

i tried to fire a remote event and i put (player,mouse.Hit) as arguments but when i mention mouse.Hit in the script it says its the player

and i really dont want to rescript everything bc its 300 lines +

No need to put put any arguments such as that. Try something like this (let me know if you have any questions):

  1. Have a localscript to detect when a player clicks the button to activate the black hole
  2. When a player clicks it, send an empty (No extra parameters) Remote Event to the server from the localscript
  3. Then, have a script on the server-side waiting for this event (using RemoteEvent.OnServerEvent), and then create the black hole however it is you do that.
1 Like

Something like this…

(Assuming the black hole activates when you click a GUI Button, not something like UserInputService. You can still do basically the same thing with UserInputService though with different functions)

LocalScript:

yourButton.MouseButton1Click:Connect(function())
    yourRemoteEvent.FireServer()
end)

Script:

yourRemoteEvent.OnServerEvent:Connect(function()
    -- Create Black Hole
end)
2 Likes

Have you tried copy pasting? Just copy it over to another script and swap out the variables.

yes but client script uses mouse

If you need the mouse information, just send the mouse position to the server using the remote event.

yes i did that but it recives the local player

You should do thorough reading of the API. OnServerEvent takes in two parameters, which are the Player and a Tuple. The reason as to why you are receiving the player is because it is the first argument of the OnServerEvent. You need to set your first argument as the player and your second argument as mouse.Hit.Position, like so:

remoteEvent.OnServerEvent:Connect(function(player, mousePosition)
	--code
end)

This will allow you to functionally use mousePosition.

yea i did it like that
player,mouse

when i fired the event i did (player,mouse.Hit)

and when i type part.CFrame = Hit

it says that i need to put a cframe not a instance

when i print mouse it prints the local player

FireServer takes in one parameter, which are the arguments that will be passed through to the OnServerEvent. You do not need to specify the player when firing said remote to the server.

--localscript
remoteEvent:FireServer(mouse.Hit.Position)

--serverscript
remoteEvent.OnServerEvent:Connect(function(player, mousePosition)
	--[[mousePosition is the mouse.Hit.Position that 
	   we passed in the first code block.]]
end)
1 Like

wow thank you much it worked

30

1 Like