Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make a Pet System with Filtering Enabled?

Asked by 5 years ago

I have been wanting to create a pet system for a game I am currently developing. The problem is that I have no idea how I would go about doing this while using Filtering Enabled.

Different games have implemented this feature before and I thought it would be fun to try and make one myself. I have been going around doing some searches but I have only found people moving the pet from a local script. That means the pet would only be moved from a locally and all the other clients wouldn't see it move

I want every person in the game to be able to see the pet without spamming the server with remote events and I also don't wan't the pet to be welded to the player.

What do you think the best way to do this would be?

2 answers

Log in to vote
0
Answered by
Dfzoz 489 Moderation Voter
5 years ago

Filtering enabled is quite easy. You just have to insert a remoteevent or remotefunction (in case you want to give a response to the local script) and bind them with a server script and a local script. For example you can use this code to bind the spawn function of a pet:

--Server Script Code
function newPet(player,petName)
--insert the code to add a pet here
--return pet(will reference the pet you spawned back to the local script) 
end
remoteFunction.OnServerInvoke = newPet

You referenced the event and bound the function to it using OnServerInvoke. Now you need to create the localscript that will fire the event:

function onClick()
local pet = remoteFunction:InvokeServer(petName)
if pet ~= nil then
print("You spawned your pet") 
else ("You couldn't spawn a pet") 
end
end
button.MouseButton1Click:Connect(onClick) 

When a remoteFunction or remoteEvent is called, the first argument of the function bound to it will always be the player that called it. You can add more arguments, like the name of the pet you want to spawn. Be aware that if you want to check if the player have money or other requirements to spawn the pet you should do it on the server scripts, because if you do it locally hackers will have a much easier time exploiting your game. They would hack the money, and as it was checked local side, the money that was exploited would be accepted and the pet would be bought. With a server script check, even if the hacker exploited the money on the client, the variable wont change to the server, and he wont be able to buy the pet.

0
The problem is moving the pet(s). For all the players in-game to be able to see the pets move the server has to move them. What would the best way to do that be? Nilsen84 1 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

I figured it out. Here is how I did it:

I have a server script that clones the pet into the players character. The server then makes the player the network owner of the pet by using the BasePart:SetNetworkOwer() function.

The player can now move the pet from a local script and it will be replicated to all other clients

Answer this question