I got a problem with a workspace tool buyer script

the script is:

local buyBlock = script.Parent
local clickDetect = buyBlock:WaitForChild("ClickDetector")
local config = buyBlock:WaitForChild("Configuration")
local DataStoreService = game:GetService("DataStoreService")
local BadgeService = game:GetService("BadgeService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local BadgeID = config.BadgeID.Value
local coilStorage = ReplicatedStorage:WaitForChild("Toolss")
local coilStore = DataStoreService:GetDataStore("playerCoils")

local player = game.Players.LocalPlayer
local character = player.Character
local leaderstats = character:WaitForChild("leaderstats")
local money = leaderstats:WaitForChild(config.leaderstatCurrency.Value)
local tool = config.tool2buy.Value
local index = config.Index
local plrcoils = coilStore:GetAsync(player.UserId)

clickDetect.MouseClick:Connect(function()
	if money.Value >= config.priceAmount.Value and (not plrcoils or not plrcoils["mainCoils"] or not plrcoils["mainCoils"][index]) then
		plrcoils = plrcoils or {}
		plrcoils["mainCoils"] = plrcoils["mainCoils"] or {}
		plrcoils["mainCoils"][index] = index
		local success, err = pcall(function()
			coilStore:SetAsync(player.UserId, plrcoils["mainCoils"])
		end)
		if not success then
			warn("Unable to save data to datastore: " .. err .. "Player: " .. player .. "Player Coils: " .. plrcoils)
		--	player:Kick("An unexpected error occured. Maybe try rejoining.")
		else
			_G.coilStoreLocal[player.userId] = plrcoils
			print("bought")

			if config.deductCurrency.Value == true then
				money.Value = money.Value - config.priceAmount.Value
			end

			tool:Clone().Parent = player.Backpack
			buyBlock:WaitForChild("moneySound"):Play()
			script.Parent.Material = Enum.Material.Neon
			script.Parent.Part_green.Material = Enum.Material.Neon
			task.wait(0.1)
			script.Parent.Material = Enum.Material.SmoothPlastic
			script.Parent.Part_green.Material = Enum.Material.SmoothPlastic

			BadgeService:AwardBadge(player.UserId, BadgeID)
			-- Teleport the player after a delay
		end
	else
		-- print("not enough money or coil owned")
		buyBlock:WaitForChild("errorSound"):Play()
		script.Parent.Material = Enum.Material.Neon
		script.Parent.Part_green.Material = Enum.Material.Neon
		script.Parent.BrickColor = BrickColor.new("Really red") 
		script.Parent.Part_green.BrickColor = BrickColor.new("Really red")
		task.wait(0.1)
		script.Parent.Material = Enum.Material.SmoothPlastic
		script.Parent.Part_green.Material = Enum.Material.SmoothPlastic
		script.Parent.BrickColor = BrickColor.new("Forest green")
		script.Parent.Part_green.BrickColor = BrickColor.new("Parsley green")
	end
end)

and when i active it nothing happens and it gives 0 errors, i would be glad if someone help me

PS. “coils” saves on a table, in another script

Hey again,

looks like this is a local script, local scripts do not work in workspace. switch that to a server script.

and to get the player MouseClick event gives a parameter of the player who clicked when fired.

clickDetect.MouseClick:Connect(function(playerwhoclicked)

ohhhhhh heres why thanks again ig

so how the sentence would be?

1 Like

Your SERVER script should look like this:

local buyBlock = script.Parent
local clickDetect = buyBlock:WaitForChild("ClickDetector")
local config = buyBlock:WaitForChild("Configuration")
local DataStoreService = game:GetService("DataStoreService")
local BadgeService = game:GetService("BadgeService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local BadgeID = config.BadgeID.Value
local coilStorage = ReplicatedStorage:WaitForChild("Toolss")
local coilStore = DataStoreService:GetDataStore("playerCoils")

clickDetect.MouseClick:Connect(function(player)
	local character = player.Character
	local leaderstats = character:WaitForChild("leaderstats")
	local money = leaderstats:WaitForChild(config.leaderstatCurrency.Value)
	local tool = config.tool2buy.Value
	local index = config.Index
	local plrcoils = coilStore:GetAsync(player.UserId)

	if money.Value >= config.priceAmount.Value and (not plrcoils or not plrcoils["mainCoils"] or not plrcoils["mainCoils"][index]) then
		plrcoils = plrcoils or {}
		plrcoils["mainCoils"] = plrcoils["mainCoils"] or {}
		plrcoils["mainCoils"][index] = index
		local success, err = pcall(function()
			coilStore:SetAsync(player.UserId, plrcoils["mainCoils"])
		end)
		if not success then
			warn("Unable to save data to datastore: " .. err .. "Player: " .. player .. "Player Coils: " .. plrcoils)
		--	player:Kick("An unexpected error occured. Maybe try rejoining.")
		else
			_G.coilStoreLocal[player.userId] = plrcoils
			print("bought")

			if config.deductCurrency.Value == true then
				money.Value = money.Value - config.priceAmount.Value
			end

			tool:Clone().Parent = player.Backpack
			buyBlock:WaitForChild("moneySound"):Play()
			script.Parent.Material = Enum.Material.Neon
			script.Parent.Part_green.Material = Enum.Material.Neon
			task.wait(0.1)
			script.Parent.Material = Enum.Material.SmoothPlastic
			script.Parent.Part_green.Material = Enum.Material.SmoothPlastic

			BadgeService:AwardBadge(player.UserId, BadgeID)
			-- Teleport the player after a delay
		end
	else
		-- print("not enough money or coil owned")
		buyBlock:WaitForChild("errorSound"):Play()
		script.Parent.Material = Enum.Material.Neon
		script.Parent.Part_green.Material = Enum.Material.Neon
		script.Parent.BrickColor = BrickColor.new("Really red") 
		script.Parent.Part_green.BrickColor = BrickColor.new("Really red")
		task.wait(0.1)
		script.Parent.Material = Enum.Material.SmoothPlastic
		script.Parent.Part_green.Material = Enum.Material.SmoothPlastic
		script.Parent.BrickColor = BrickColor.new("Forest green")
		script.Parent.Part_green.BrickColor = BrickColor.new("Parsley green")
	end
end)

yea but nothing happens, hold on look at the parents:

image

dont mind that there is no script inside of “CoilBuyer”

Looks like the script is disabled, the clickdetector inside the part looks like this script.Parent.ClickDetector, your script should have the same parent as the click detector.

its not that one, now i gotta go ill try chatting here trough phone

1 Like

yo im back are you still there?

local buyBlock = script.Parent
local sel = buyBlock:WaitForChild(“Part_green”)

local services = {
game:GetService(“Players”);
game:GetService(“ReplicatedStorage”);
game:GetService(“BadgeService”);
game:GetService(“DataStoreService”);
}

local config = buyBlock:WaitForChild(“Configuration”)

local coilStore = services[4]:GetDataStore(“playerCoils”)

local coilStorage = services [2]:WaitForChild(“Toolss”)

local BadgeID = config.BadgeID.Value or use attribute — config:GetAttribute(“BadgeID”)

local price = config.priceAmount.Value
— config:GetAttribute(“price”)

local clickDetect = buyBlock:WaitForChild(“ClickDetector”) - - don’t use this use more proximity prompts .tiggered

function changepart(Part,bool)
if bool == false then

buyBlock:WaitForChild(“errorSound”):Play()

Part.BrickColor.new(“Really red”)
Part.Material = Enum.Material.Neon
Wait (1)
Part.Material = Enum.Material. SmoothPlastic
Wait (0.1)
Part.BrickColor.new(“Forest green”)
else
buyBlock:WaitForChild(“moneySound”):Play ()

Part.Material = Enum.Material.Neon
Wait(1)
Part.Material = Enum.Material. SmoothPlastic
end

function getaward (player,badge)
Wait()
If not services[3] :UserHasBadgeAsync(player.UserId, badgeId) then
services[3]:AwardBadge(player.UserId,badge)
end
end

Function sell (player)

local character = player.Character

local leader= player:FindFirstChild(“leaderstats”)
local money = leader:FindFirstChild(“money”)
If leader and Money then
If money.Value > price then
Money.Value -= config.priceAmount.Value

changepart(Part,true)

coilStorage :Clone().Parent = backpack
coilStorage :Clone().Parent = player.Character

getaward (player, BadgeID) — then you don’t need use data store for it because If services[3] :UserHasBadgeAsync(player.UserId, badgeId) then give back the tool on joining

else

changepart(Part,false)

end

clickdetect.mouseclick:Connect(function(player)

sell(player)

Or

proximityprompt.triggered:connect(function (player)

sell (player)

end)

Services [1].playeradded:connect( function(plr)

local x = Instances.new (folder,plr
x.name =
Leaderstats

Y= Instance.new(numvalue,x)
Y.name= money

end)