Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to use RemoteEvent in a Tool's script?

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?

5 comments

0

Why is your seed in Lighting?

0

the tool's in starterpack and onced the tool is used: the tool calls the newseed

0

But why is the seed in Lighting?

0

I will use it for the shop gui

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?

1 answer

✓ Accepted answer
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

This discussion is preserved as it was. New answers, comments, and votes are closed.