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

How to use RemoteEvent in a Tool's script?

Asked by 6 years ago
Edited 6 years ago

So, I might freak out cause I always think if I use :Clone() to a script in a tool. Not all the players might see it in the in-game server, and how to use RemoteEvent to a Tool's script if the players won't see the cloned model/part? This is a sample of my script without RemoteEvent.

01local t = game:GetService("TweenService")
02script.Parent.Deactivated:Connect(function()
03    print("Planted")
04    local oldseed = script.Parent
05    local seed = script.Parent.Handle:Clone()
06    seed.Parent = game.Workspace
07    seed.CFrame = game.Players.LocalPlayer.Character.Starling_Seed.Handle.CFrame
08    seed.CanCollide = false
09    wait(0.2)
10    seed.Anchored = true
11    wait(0.1)
12    oldseed:Destroy()
13    wait(5)
14    seed.Anchored = false
15    local Mesh =  seed
View all 38 lines...

I use :Clone(), so my game will be Filtering Enabled. Other players might not see the cloned object?

0
Why is your seed in Lighting? User#19524 175 — 6y
0
the tool's in starterpack and onced the tool is used: the tool calls the newseed cherrythetree 130 — 6y
0
But why is the seed in Lighting? User#19524 175 — 6y
0
I will use it for the shop gui cherrythetree 130 — 6y
1
Shouldn't be using Lighting as storage. Where did you get the idea that this was a good place to store objects, when we have services like ReplicatedStorage and ServerStorage? User#19524 175 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago
1local newseed = game.Lighting.CloneSeedFruit.Starling_Seed:Clone()

Use ReplicatedStorage it is seen by both client and server

Make sure the script isn't a LocalScript since the tool will be in workspace(Character is in workspace) a script will allow everyone to see it when cloned.

So what I would do is you can make a localscript fired a RemoteEvent and that will just send the player LocalScript:

1script.Parent.Deactivated:Connect(function()
2script.Parent.RemoteEvent:FireServer()
3end)

Script:

01local t = game:GetService("TweenService")
02script.Parent.RemoteEvent.OnServerEvent:Connect(function(plr)
03    print("Planted")
04    local oldseed = script.Parent
05    local seed = script.Parent.Handle:Clone()
06    seed.Parent = game.Workspace
07    seed.CFrame = plr.Character.Starling_Seed.Handle.CFrame
08    seed.CanCollide = false
09    wait(0.2)
10    seed.Anchored = true
11    wait(0.1)
12    oldseed:Destroy()
13    wait(5)
14    seed.Anchored = false
15    local Mesh =  seed
View all 38 lines...

Just adjust that to fit your tool So you will have LocalScript Script RemoteEvent

Ad

Answer this question