I’m new to scripting and I have some trouble making a sell area for my game. I have a local script inside the part(sell area) that fires a remote event to change the player’s money/leaderstats. The event isn’t firing and I think it’s because touch detection isn’t working. Here is the local script code:
local sell = script.Parent
local rs = game:GetService(“ReplicatedStorage”)
local sellevent = rs:WaitForChild(“Sell”)
sell.Touched:Connect(function(hit)
print(“touch deceted”)
if hit.Parent == game.Players.LocalPlayer.Character then
sellevent.FireServer()
print(“eventFired”)
end
end)
and the code with the leaderstats which is in StarterPack:
local replicatedstorage = game:GetService(“ReplicatedStorage”)
local remotedata = game:GetService(“ServerStorage”):WaitForChild(“RemoteData”)
local cooldown = 0.5
local sellevent = replicatedstorage:WaitForChild(“Sell”)
replicatedstorage.Remotes.Syrup.OnServerEvent:Connect(function(player)
if not remotedata:FindFirstChild(player.name) then return “NoFolder” end
local debounce = remotedata[player.Name].Debounce
if not debounce.Value then
debounce.Value = true
But tbh, its probably better overall if you just handle the touch event on the server in the very beginning, making it less vulnerable to infinite money expoits and possibly saving you from using a remote event.
local script in workspace wont work instead of a local try using a normal script add a script in the part and write this:
local sell = script.Parent
sell.Touched:Connect(function(hit)
print(“touch deceted”)
if game.Players:GetPlayerFromCharacter(hit) then
local plr = game.Players:GetPlayerFromCharacter(hit)
plr.leaderstats.Syrup.Value += player.leaderstats.Money.Value
---player.leaderstats.Syrup.Value = 0
print("finish giving money")
end
end)
Sorry I hate to be one of those people but how would I do something like this? My understanding is that when you use a path in a local script you have to define it using parents and children. So how would I call with a local script if they run in workspace?