My sell script will not work. I was following a tutorial however I could not seem to figure out what the error was. There is nothing in the output, but this is the script:
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
game.ReplicatedStorage.BindableEvents.Sell:Fire(player)
end
end)
2 Likes
is it a server script or a local script?
2 Likes
Server script. Should I change it?
2 Likes
Nope keep it a server script. i am gonna test out your script.
Ok. You may also need my script in ServerScriptService.
You are firing a remote event or remote function. if yes can u send the remote event code?
I have it as a Bindable Event. I am assuming you mean this code in serverscriptservice:
local datastore = game:GetService("DataStoreService"):GetDataStore("Divine")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Parent = player
leaderstats.Name = "leaderstats"
local cash = Instance.new("IntValue")
cash.Parent = leaderstats
cash.Name = "Cash"
local buildpower = Instance.new("IntValue")
buildpower.Parent = leaderstats
buildpower.Name = "BuildPower"
local rebirths = Instance.new("IntValue")
rebirths.Parent = leaderstats
rebirths.Name = "Rebirths"
local debounce = Instance.new("BoolValue")
debounce.Value = false
debounce.Name = "Debounce"
debounce.Parent = player
local key = "user"..player.UserId
local storeditems = datastore:GetAsync(key)
if not storeditems then
cash.Value = 0
rebirths.Value = 0
buildpower.Value = 0
end
if storeditems then
cash.Value = storeditems[1]
rebirths.Value = storeditems[2]
buildpower.Value = storeditems[2]
else
local items = {cash.Value, rebirths.Value, buildpower.Value}
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local items = {player.leaderstats.Cash.Value, player.leaderstats.Rebirths.Value, player.leaderstats.BuildPower.Value}
datastore:SetAsync(player.UserId,items)
end)
1 Like
Sorry, wrong code i think
local ReplicatedStorage = game.ReplicatedStorage
ReplicatedStorage.RemoteEvents.BuildPower.OnServerEvent:Connect(function(player, valueFolder)
if player.Debounce.Value == false then
player.leaderstats.BuildPower.Value = valueFolder.BuildPower.Value + player.leaderstats.BuildPower.Value*(player.leaderstats.Rebirths.Value + 1)
player.Debounce.Value = true
wait (valueFolder.CoolDown.Value)
player.Debounce.Value = false
end
end)
ReplicatedStorage.BindableEvents.Sell.Event:Connect(function(player)
if player == nil then
player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + player.leaderstats.BuildPower.Value *2
player.leaderstats.BuildPower.Value = 0
end
end)
1 Like
yes thanks lemme check it out. i will tell you if i see anything wrong
Try using āFireClientā and not āFireā in the first code u sent
FireClient is not a valid member of BindableEvent āReplicatedStorage.BindableEvents.Sellā
send the code you used please.
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
game.ReplicatedStorage.BindableEvents.Sell:FireClient(player)
end
end)
Is this a remote event or a remote function? if a remote function replace the FireClient with InvokeClient
1 Like
regexman
(reg)
January 27, 2022, 7:53pm
16
Itās a bindableevent, so :Fire is correct.
If you are talking about the āsellā event its a bindable event. I just started scripting a couple weeks ago so correct me if Iām wrong
he said that :Fire
returned āFireClient is not a valid member of BindableEvent āReplicatedStorage.BindableEvents.Sellāā
1 Like
Youāre checking if the player is nill but then do code for the player. I assume you want it so that it only runs if the player is there, in which case itād be as such:
ReplicatedStorage.BindableEvents.Sell.Event:Connect(function(player)
if not player then return end
player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + player.leaderstats.BuildPower.Value *2
player.leaderstats.BuildPower.Value = 0
end)
Workspace.Model.Model.Part.Script:1: attempt to index nil with āBindableEventsā