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 5 years ago
Edited 5 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.

local t = game:GetService("TweenService")
script.Parent.Deactivated:Connect(function()
    print("Planted")
    local oldseed = script.Parent
    local seed = script.Parent.Handle:Clone()
    seed.Parent = game.Workspace
    seed.CFrame = game.Players.LocalPlayer.Character.Starling_Seed.Handle.CFrame
    seed.CanCollide = false
    wait(0.2)
    seed.Anchored = true
    wait(0.1)
    oldseed:Destroy()
    wait(5)
    seed.Anchored = false
    local Mesh =  seed
    local boduy = Instance.new("BodyPosition", Mesh)
    boduy.MaxForce = Vector3.new(5000, 5000, 5000)
    boduy.Position = Vector3.new(seed.CFrame.X,100,seed.CFrame.Z)
    wait(2)
    Mesh.Anchored = true
    boduy:Destroy()
    while true do
        wait(5)
        local goal = {}
        goal.Size = Vector3.new(100.5, 50.96, 100.751)
        goal.Orientation = Vector3.new(90, game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame.Y,90)
        goal.Color = Color3.fromRGB(255,0,0)
        local g = t:Create(Mesh, TweenInfo.new(50), goal)
        g:Play()
        wait(20)
        local newseed = game.Lighting.CloneSeedFruit.Starling_Seed:Clone()
        newseed.Handle.CFrame = Mesh.CFrame
        newseed.Parent = game.Workspace
        print("Cloned Seed!")
        wait(105)
        newseed:Destroy()   
    end
end)

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 — 5y
0
the tool's in starterpack and onced the tool is used: the tool calls the newseed cherrythetree 130 — 5y
0
But why is the seed in Lighting? User#19524 175 — 5y
0
I will use it for the shop gui cherrythetree 130 — 5y
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 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago
local 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:

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

Script:

local t = game:GetService("TweenService")
script.Parent.RemoteEvent.OnServerEvent:Connect(function(plr)
    print("Planted")
    local oldseed = script.Parent
    local seed = script.Parent.Handle:Clone()
    seed.Parent = game.Workspace
    seed.CFrame = plr.Character.Starling_Seed.Handle.CFrame
    seed.CanCollide = false
    wait(0.2)
    seed.Anchored = true
    wait(0.1)
    oldseed:Destroy()
    wait(5)
    seed.Anchored = false
    local Mesh =  seed
    local boduy = Instance.new("BodyPosition", Mesh)
    boduy.MaxForce = Vector3.new(5000, 5000, 5000)
    boduy.Position = Vector3.new(seed.CFrame.X,100,seed.CFrame.Z)
    wait(2)
    Mesh.Anchored = true
    boduy:Destroy()
    while true do
        wait(5)
        local goal = {}
        goal.Size = Vector3.new(100.5, 50.96, 100.751)
        goal.Orientation = Vector3.new(90, plr.Character.HumanoidRootPart.CFrame.Y,90)
        goal.Color = Color3.fromRGB(255,0,0)
        local g = t:Create(Mesh, TweenInfo.new(50), goal)
        g:Play()
        wait(20)
        local newseed = game.Lighting.CloneSeedFruit.Starling_Seed:Clone()
        newseed.Handle.CFrame = Mesh.CFrame
        newseed.Parent = game.Workspace
        print("Cloned Seed!")
        wait(105)
        newseed:Destroy()   
    end
end)

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

Ad

Answer this question