Roblox script doing damage in studio but not in the app

alright so ive made a topic got a script and that script worked in studio but in the roblox app it doesn’t work. what did i do wrong??

1 Like

Could you perhaps share the Script itself?

1 Like
local tool = script.Parent
local da = true
tool.Touched:Connect(function(OtherPart)
	if OtherPart.Parent:FindFirstChild("Humanoid") and da == true then
		da = false
		local player = game.Players:GetPlayerFromCharacter(OtherPart.Parent)
		OtherPart.Parent.Humanoid:TakeDamage(10)
		wait(2)
		da = true
		if OtherPart.Parent:WaitForChild("Humanoid",5).Health == 0 then
			player.leaderstats.Gold.Value = player.leaderstats.Gold.Value + 50
			wait(0.4)
			script.Parent.Parent.Main.Enabled = true
			wait(1)
			script.Parent.Parent.Main.Enabled = false
		end
	end
end)

Replace it with player.Character:FindFirstChild("Humanoid")

replace with
if player.Character:WaitForChild("Humanoid",5).Health == 0 then

yo btw i got an off topic question about remote events. im trying to like, after you kill the player you get like 50 coins or something. but idk how to do that, could ya help?

1 Like

Anyway. when i tried replacing the script with what you said i got this error:

Players.Mob1leN0OB.Backpack.Baseball Bat.Kill part.LocalScript:7: attempt to index nil with ‘Character’

1 Like

yeah sure.

local  coinevent = instance.new("RemoteEvent")
coinevent.Name = "coinevent"
coinevent.Parent = game.ReplicatedStorage
character:WaitForChild("Humanoid").Died:connect(function()
game.ReplicatedStorage.coinevent:FireServer(plr)
end

Server script:

game.ReplicatedStorage:FindFirstChild("coinevent").OnServerEvent:Connect(function(plr)
plr.leaderstats.Gold.Value = plr.leaderstats.Gold.Value+50
end

I’m fairly certain my ends are not correct, so you can fix accordingly but that is how you should do it.

Im not trying to be annoying or something but im sometimes wrong.

local  coinevent = instance.new("RemoteEvent")
coinevent.Name = "coinevent"
coinevent.Parent = game.ReplicatedStorage
character:WaitForChild("Humanoid").Died:connect(function()
game.ReplicatedStorage.coinevent:FireServer(plr)
end

do i put this in serverscriptservice?

lol i just realized I made an error.

local  coinevent = instance.new("RemoteEvent")
coinevent.Name = "coinevent"
coinevent.Parent = game.ReplicatedStorage

this should go in a seperate server script, the

character:WaitForChild("Humanoid").Died:connect(function()
game.ReplicatedStorage.coinevent:FireServer(plr)

can not be called from a server script as it fires a remote event, server scripts can only receive and translate those remote events.
Keep in mind: using fireserver for leaderstats is extremely insecure, i’d reccomend researching security measures to take and follow.

about the

character:WaitForChild("Humanoid").Died:connect(function()
game.ReplicatedStorage.coinevent:FireServer(plr)

shouldn’t it be like "OtherPart.Parent:WaitForChild(“Humanoid”).Died:Connect(function)?

no.

local character = player.Character

yo btw i got this script in serverscriptservice called “GiveMoney”


local event = Instance.new("RemoteEvent")
event.Name = "GiveMoneyEvent"
event.Parent = game.ReplicatedStorage

local function giveMoney()
	game.Players.PlayerAdded:Connect(function(player)
		local gold = player:WaitForChild("leaderstats").gold
		player.leaderstats.Gold.Value = player.leaderstats.Gold.Value + 50
	end)
end

event.OnServerEvent:Connect(giveMoney)

would i just fire it by doing Local event = game.ReplicatedStorage:WaitForChild("GiveMoneyEvent")

if char:WaitForChild("Humanoid",5).Health == 0 then
			event:FireServer()

Sorry that its kind of messy lol.

local event = Instance.new("RemoteEvent")
event.Name = "GiveMoneyEvent"
event.Parent = game.ReplicatedStorage

function giveMoney(player)
	local gold = player:WaitForChild("leaderstats").Gold
	player.leaderstats.Gold.Value += 50
end

event.OnServerEvent:Connect(giveMoney)

Alright so when i use player.character i get an error “attempt to index with character” it gets fixed when using a localscript, but when i use a localscript then i cant fire the Event.

player.Character not player.character

obraz

:wait() is deprecated. use :Wait()