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

How to define a RemoteEvent in purchasing tools?

Asked by 6 years ago
Edited 6 years ago

My game is filtered Enabled.

I have a store ingame that is purchased with tools. You click a part [named Buy] to purchase the item. How do I get this Tool to be visible with everyone in game Everytime I try, its not working The code has a intvalue named Price and a String Value for the name

Thanks for answering in advance. LOCAL SCRIPT


local db= true local button=script.Parent local price=button:WaitForChild("Price") local item=button:WaitForChild("ItemName") local rs=game:GetService("ReplicatedStorage") local tool = script.Parent -- the tool tool.ClickDetector.MouseClick:connect (function(player) if player.leaderstats.Coins.Value>=price.Value then player.leaderstats.Coins.Value=player.leaderstats.Coins.Value-price.Value db = false workspace.tool:FireServer(tool)-- Fires the RemoteEvent wait(3) -- wait that extra three seconds db = true end end)

ServerScriptService


workspace.tool.OnServerEvent:Connect(function(player, tool) -- tool is the tool, player is the player that sent the event tool.BrickColor = BrickColor.new("Bright red") -- poof! local item=game:GetService("ReplicatedStorage"):WaitForChild(item.Value) -- ERROR LINE item.Clone().Parent = player.StarterGear -- poof! item:Clone().Parent=player.Backpack -- poof! wait(3) -- poof! tool.BrickColor = BrickColor.new("Bright green") -- poof! end)

ServerScriptService.Tool:5: attempt to index global 'item' (a nil value) Now the tools will not spawn in the backpack at all now, and I made a RemoteEvent in the workspace and Replicated Storage called tool

1 answer

Log in to vote
0
Answered by 6 years ago

(Re-posting this after I deleted it)

Err...

If the remote event is called "tool" then...

workspace.tool:FireServer(tool)

When I gave you this code, I forgot to mention the explanation of the code.

So here it is:

-- In the LocalScript
local db= true



local button=script.Parent
local price=button:WaitForChild("Price")
local item=button:WaitForChild("ItemName")
local rs=game:GetService("ReplicatedStorage")
local tool = script.Parent -- the tool


tool.ClickDetector.MouseClick:connect (function(player)
    if player.leaderstats.Coins.Value>=price.Value then
        player.leaderstats.Coins.Value=player.leaderstats.Coins.Value-price.Value
        db = false

        workspace.RemoteEvent:FireServer(tool) -- Fires the RemoteEvent's server thingiemadoodle, "tool" being a parameter so that the RemoteEvent knows what tool fired the event and therefore can connect with that tool.
        wait(3) -- wait that extra three seconds
        db = true
        end
end)
--In a server script
workspace.RemoteEvent.OnServerEvent:Connect(function(player, tool) -- tool is the tool, player is the player that sent the event
        tool.BrickColor = BrickColor.new("Bright red") -- poof!
        local item=game:GetService("ReplicatedStorage"):WaitForChild(item.Value) -- poof!
        item.Clone().Parent = player.StarterGear -- poof!
        item:Clone().Parent=player.Backpack -- poof!
        wait(3) -- poof!
        tool.BrickColor = BrickColor.new("Bright green") -- poof!
end
0
it seems the server script and local script arent communicating properly, though. it's giving me WaitForChild(item.Value) it is a unknown global item in serverstoragescript robloxquestionnaire1 30 — 6y
Ad

Answer this question